通常,在处理Java IO代码时,这是我写的
FileOutputStream out = null;
try
{
out = new FileOutputStream("myfile.txt");
// More and more code goes here...
}
catch (Exception e)
{
}
finally
{
// I put the close code in finally block, to enture the opened
// file stream is always closed even there is exception happened.
if (out != null) {
// Another try catch block, troublesome.
try {
out.close();
} catch (IOException ex) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,当我尝试关闭文件流时,我需要处理另一个try ... catch块.
看起来很麻烦:(
有什么办法可以避免吗?将close代码放在非finally块中感觉不舒服,因为其他代码引起的异常将无法调用"close".
当我想在我的本地变更集上创建一个补丁时,我真的必须先提交,任何我都可以创建补丁.我可以在TortoiseHg下知道如何在不执行提交的情况下创建补丁吗?
我面临的问题完全相同
它并不总是发生.您需要将手机切换到飞行模式,或关闭wifi,等待几个小时,只会出现问题.将显示以下错误消息.
无法查询iventory:IabResult:刷新iventory时出错(查询商品价格).(回复:6:错误)
作者建议使用
List<String> skulist = new ArrayList<String>();
skulist.add("my_sku_name1");
skulist.add("my_sku_name2");
mHelper.queryInventoryAsync(true, skulist, mGotInventoryListener);
Run Code Online (Sandbox Code Playgroud)
解决问题.
但是,它对我不起作用.同样的问题仍然存在.
有关此问题的任何解决方法吗?谢谢.
以前,我有一套Google Drive API代码,在以下情况下可以正常使用
几天前,我遇到方案2不再工作(更新appdata中的上一个文件),而其他方案仍然没有问题.我将得到以下异常.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error
{
"code": 500,
"errors": [
{
"domain": "global",
"message": "Internal Error",
"reason": "internalError"
}
],
"message": "Internal Error"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:423)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at org.yccheok.jstock.gui.Utils.updateFile(Utils.java:1414)
Run Code Online (Sandbox Code Playgroud)
我正在使用both DRIVE和DRIVE_APPDATAscope - authorizeDrive()
代码如下
1414号线正在抛出例外情况
com.google.api.services.drive.model.File updatedFile = service.files().update(fileId, file, mediaContent).setNewRevision(false).execute();
Run Code Online (Sandbox Code Playgroud)
使用查询在appdata中搜索上一个文件title contains 'jstock-fe78440e-e0fe-4efb' and trashed = false and 'appdata' …
我希望
我可以知道,我应该考虑什么,选择ArrayList(在插入前显式执行包含检查)或LinkedHashSet?
谢谢.
我想知道Chrome Angry Bird背后使用的技术是什么?
它使用HTML5画布进行显示.对于编程逻辑代码,它似乎不是闪存.或者,愤怒的小鸟队在JavaScript中重写他们的代码?
我想获得所有可能的货币.
Java 7提供了这样的功能.
public static Set<java.util.Currency> java.util.Currency.getAvailableCurrencies()
Run Code Online (Sandbox Code Playgroud)
但是,我仍在使用Java 6进行开发和部署.我可以知道如何获得所有可能的货币吗?代码示例最受欢迎.
目前,我的应用正在使用
我使用以下代码来执行GoogleApiClient连接.
public class GoogleApiClientFragment extends Fragment implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
public interface ConnectionCallbacks {
void onConnected(GoogleApiClient googleApiClient, int action);
void onCancel(int action);
}
public static GoogleApiClientFragment newInstance(String accountName, int action) {
GoogleApiClientFragment googleApiClientFragment = new GoogleApiClientFragment();
Bundle bundle = new Bundle();
bundle.putString(INTENT_EXTRA_ACCOUNT_NAME, accountName);
bundle.putInt(INTENT_EXTRA_ACTION, action);
googleApiClientFragment.setArguments(bundle);
return googleApiClientFragment;
}
/**
* Handles resolution callbacks.
*/
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data); …Run Code Online (Sandbox Code Playgroud) 最近,我在生产者/消费者队列系统上做了快速实现.
<?php
namespace Queue;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;
class Amqp
{
private $connection;
private $queueName;
private $delayedQueueName;
private $channel;
private $callback;
public function __construct($host, $port, $login, $password, $queueName)
{
$this->connection = new AMQPStreamConnection($host, $port, $login, $password);
$this->queueName = $queueName;
$this->delayedQueueName = null;
$this->channel = $this->connection->channel();
// First, we need to make sure that RabbitMQ will never lose our queue.
// In order to do so, we need to declare it as durable. To do so we pass
// …Run Code Online (Sandbox Code Playgroud) 目前,我使用Rectangle和Rectangle2D(Rectangle2D.Double)交换.
我想知道在选择正确的数据类型时我会考虑什么?我没有看到任何明显的区别,除了Rectangle(Rectangle2D的子类)有更多的API函数.
谢谢.