java往一个.txt文件写入内容

1、

try {
         String newPath = parentFilePath + "\\" + fileName;
            File file = new File(newPath);
            if (!file.exists()) {
                file.createNewFile();
            }
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false)));
            out.write(conent);
        } catch (Exception e) {
            System.out.println("写入LOG失败:" + conent);
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                System.out.println("关闭写文件失败");
            }
        }

  

posted @ 2022-12-25 13:46  信铁寒胜  阅读(261)  评论(0)    收藏  举报