【发布时间】:2016-10-09 19:30:01
【问题描述】:
您好,我正在尝试使用 FileOutputStream 通过网络发送数据。每当使用链接的文件创建 FileOutputStream 时,它都会删除找到的所有数据,就好像它正在用新文件替换旧文件一样。
有人可以帮忙吗?这是代码。
File videoFile = new File (Current_video_file);
log.info(videoFile.toString());
InputStream is = null;
OutputStream outS = null;
try{
is = socket.getInputStream();
} catch (IOException e){
e.printStackTrace();
}
try{
outS = new FileOutputStream(videoFile);
} catch (IOException e){
e.printStackTrace();
}
byte [] videoLength = new byte [16*1024];
log.info("About to send");
int count;
while((count = is.read(videoLength)) > 0){
log.info("Sending Message");
outS.write(videoLength, 0, count);
}
log.info("Data Sent");
outS.close();
is.close();
【问题讨论】:
-
提示:你可以自助;例如,开始阅读您打算使用的库类/方法的 javadoc。换句话说:你做出假设这个或那个应该如何工作。事情是:现实并不关心你的假设。这并不意味着粗鲁,而是对程序员的重要教训:始终验证您的想法,其他组件的实际行为方式。尤其是当它有很好的文档时,这部分真的很容易。
标签: java sockets fileoutputstream