产生特定大小的文件,在测试某些test case的时候会非常有用,可以使用RandomAccessFile类来实现:
class="java" name="code">package io; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; public class BigFileTester { public static void main(String[] args) throws FileNotFoundException, IOException { int cap = 3*1024*1024; long start2 = System.currentTimeMillis(); RandomAccessFile r = new RandomAccessFile("C:\\test2.txt", "rw"); r.setLength(cap); r.close(); long duration2 = System.currentTimeMillis() - start2; System.out.println(duration2); } }
?