| 内容 | JAVA创建固定长度文件的方法,具体代码如下:
 //
 // usage : java CreateAFile 2048 twokbytes.dat
 //
 import java.io.FileOutputStream;
 import java.io.IOException;
 public class CreateAFile {
 public static void main(String[] args) throws IOException {
 byte[] buf = new byte[8192];
 long n = Long.parseLong(args[0]);
 FileOutputStream fos = new FileOutputStream(args[1]);
 long m = n / buf.length;
 for (long i = 0; i < m; i++) {
 fos.write(buf, 0, buf.length);
 }
 fos.write(buf, 0, (int)(n % buf.length));
 fos.close();
 }
 }
 |