Java:清空文件内容

文章来源:https://www.cnblogs.com/hello-tl/p/9139432.html 

import java.io.*;

public class FileBasicOperation {
  /**
     * 清空文件内容
     * @param fileName
     */
    public static void clearInfoForFile(String fileName) {
        File file =new File(fileName);
        try {
            if(!file.exists()) {
                file.createNewFile();
            }
            FileWriter fileWriter =new FileWriter(file);
            fileWriter.write("");
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

文章来源:https://www.cnblogs.com/hello-tl/p/9139432.html 

转载于:https://www.cnblogs.com/hello-tl/p/9139432.html

你可能感兴趣的:(Java:清空文件内容)