示例:
public class DeletePackage {
public static void main(String[] args) throws Exception {
File file = new File("D:\\PackageP13\\"); //绝对路径。
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
Scanner input = new Scanner(files[i]);
String s1 = input.nextLine();
if (s1.isEmpty()) {
System.out.println(s1 + " —— is empty ");
s1 = input.nextLine();
}
StringBuffer sb = new StringBuffer();
while (input.hasNext()) {
s1 = input.nextLine();
sb = sb.append(s1 + "\r\n");
}
input.close();
PrintWriter output = new PrintWriter(files[i]);
output.println(sb);
output.close();
}
}
}