Java对字符文件写入内容

public static void writeFile(String fileName,String content){
        FileWriter writer = null;
        try {
            writer = new FileWriter(fileName);
            writer.write(content);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(writer!=null) {
                    writer.close();
                    writer = null;
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

fileName为文件路径,content为写入的内容

posted @ 2022-05-31 17:33  杜嘟嘟  阅读(113)  评论(0编辑  收藏  举报