【发布时间】:2015-11-09 12:28:18
【问题描述】:
我是文件处理的新手。我尝试使用文件输入流和文件通道读取文件。我在以下代码中找不到错误。它运行成功,但文件尚未传输。用零字节创建新文件。请看一下代码并检查出了什么问题
public class FileTest
{
public static void main(String[] args)
{
try {
File file = new File("sss.jpg");
FileChannel inChannel=new FileInputStream(file).getChannel();
//FileChannel inChannel = in.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(1024);
while(inChannel.read(buffer) > 0) {
FileChannel outChannel=new FileOutputStream("sss1.jpg",true).getChannel();
outChannel.write(buffer);
}
}
catch(IOException ex) {}
}
}
【问题讨论】:
标签: java io filechannel