创建固定长度的文件,创建固定长度文件, //
分享于 点击 14084 次 点评:267
创建固定长度的文件,创建固定长度文件, //
// // 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(); } }
用户点评