创建指定大小的文件的代码

  1. public static void main(String[] args) {   
  2. // TODO Auto-generated method stub   
  3. MappedByteBuffer mbb;   
  4. FileChannel fc;   
  5. int length = 1 << 29// 512 MB   
  6.   
  7. try {   
  8. fc = new RandomAccessFile("/myfile.dat""rw").getChannel();   
  9. mbb = fc.map(FileChannel.MapMode.READ_WRITE, 0, length);   
  10. catch (FileNotFoundException e) {   
  11. // TODO Auto-generated catch block   
  12. e.printStackTrace();   
  13. catch (IOException e) {   
  14. // TODO Auto-generated catch block   
  15. e.printStackTrace();   
  16. }   
  17.   
  18. }   
  1. da shang
    donate-alipay
               donate-weixin weixinpay

发表评论↓↓