Java课后题第十二章:12.20(删除包语句)

示例:

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();
        }
    }
}

上一篇:面经系列(3)Java基础


下一篇:Qt工程CMake编译