import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class ChannelDemo2
{
public static void main(String [] args)
{
File fin = new File("F:"+File.separator+"4399.txt");
File fout = new File("F:"+File.separator+"5026.txt");
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(fin);
fos = new FileOutputStream(fout,false);
FileChannel fcis = fis.getChannel(); //获取 输入 输出流的通道
FileChannel fcos = fos.getChannel();
ByteBuffer sb = ByteBuffer.allocate(1024);
int len =0;
while((len = fcis.read(sb))!=-1)
{
sb.flip();
fcos.write(sb);
sb.clear();
}
fis.close();
fos.close();
fcis.close();
fcos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
原文链接:https://blog.csdn.net/w605283073/article/details/8605536
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~