【问题标题】:Java code does not get calledJava 代码不会被调用
【发布时间】:2015-02-15 15:21:16
【问题描述】:

我有问题... 我有一个套接字的 InputStream 和一个 FileOutputStream。

System.out.println("uploading...");
FileOutputStream fos = uploads.get(a); //Get the FileOutputStream from the HashMap...

byte[] buffer = new byte[0xFFF];
for (int len; (len = s.getInputStream().read(buffer)) != -1;) {
     fos.write(buffer, 0, len);
}
System.out.println("test"); //not called
fos.flush(); 
fos.close(); 
s.close(); //not called

我也尝试过使用 Apache Commons-IO 进行复制,但也没有成功...

你有什么想法吗?我认为有错误,我只是看不到它......

谢谢卢卡

【问题讨论】:

  • 不,没有例外...
  • 我刚刚将 Streams 放入带有 Auth-Object 的 Hashmap...
  • 不,输出中没有测试...
  • 哦,您应该知道文件已写入磁盘...可以,但是之后的代码不起作用...不知道为什么...
  • 谢谢提图斯!不知道要关闭另一边的socket才能关闭...

标签: java loops networking stream


【解决方案1】:

你必须要么 Try/Catch 要么 Throw that fos,所以我的猜测是你抛出异常,然后不从调用方法处理它。你的for下面的代码没有被执行的原因是抛出异常后,它立即停止当前方法,并返回到抛出异常的调用方法。

【讨论】:

    猜你喜欢
    • 2016-09-05
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多