FileChannel , 对于nio 还没有接触到, 以后有待深入.

王朝学院·作者佚名  2016-05-29
窄屏简体版  字體: 小  |  中  |  大  |  超大  

FileChannel , 对于nio 还没有接触到, 以后有待深入. 1 package test; 2 3 import java.io.FileInputStream; 4 import java.io.FileOutputStream; 5 import java.nio.ByteBuffer; 6 import java.nio.channels.*; 7 8 public class Test17 9 {10 public static void main(String[] args) throws Exception11 {12 FileChannel fc_in = new FileInputStream("d:/t.txt").getChannel();13 FileChannel fc_out = new FileOutputStream("d:/out_j.txt").getChannel();14 for (ByteBuffer buf = ByteBuffer.allocate(1024 * 1024); (fc_in.read(buf)) != -1;)15 { //缓存大小, 设定我想一次读多大的数据.16 buf.flip(); //这个相当重要, 想象一下 老式打字机, 把打字真眼移到首页17 fc_out.write(buf);18 buf.clear(); //注意这个...写完必须清楚数据, 不然程序就卡在这了.19 }20 fc_in.close();21 fc_out.close();22 }23 }

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航