读取文件以确定其包含的字节数,然后用0覆盖所有这些字节
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException;/*n o w j a v a . c o m - 时代Java 提供*/ public class Main { public static void main(String[] arguments) { try { FileInputStream file = new FileInputStream("junkfile.dat"); boolean eof = false; int size = 0; while (!eof) { int input = file.read(); if (input == -1) { eof = true; /* 时 代 Java - nowjava.com 提供 */ } else { size++; } } file.close(); FileOutputStream outFile = new FileOutputStream("junkfile.dat"); for (int i = 0; i < size; i++) { outFile.wr