一个nio 复制文件

xiaoxiao2021-02-28  4

之前做项目文件复制,因为没有学过nio,加上对并发等一些列的问题思考,采用了调用脚本

今天学习nio,复制文件,少了很多问题,think of java p553

String inPath = "/home/if/test/in.text"; String outPath = "/home/if/test/out.text"; FileChannel in = new FileInputStream(new File(inPath)).getChannel(); FileChannel out = new FileOutputStream(new File(outPath)).getChannel(); // ByteBuffer buffer = ByteBuffer.allocate(BSIZE); // in.transferTo(0,in.size(),out); or out.transferFrom(in,0,in.size()); /* while (in.read(buffer) != -1){ buffer.flip(); out.write(buffer); buffer.clear(); }*/

转载请注明原文地址: https://www.6miu.com/read-1600257.html

最新回复(0)