最简单的删掉创建新的空文件。File file = new File("./my.txt"); file.delete(); file.createNewFile();
String filename = "a.txt";RandomAccessFile rf = new RandomAccessFile(filename, "rw");FileChannel fc = rf.getChannel();//将文件大小截为0fc.truncate(0);
发的萨芬