Java 文件写入不覆盖的写法

        FileOutputStream o = null;
        File file = null;
        FileWriter fw = null;
        byte[] buff = new byte[]{};
         try {
                file = new File("F:\\data.txt");
                if (!file.exists()) {
                    file.createNewFile();
                }
                for (需要遍历的数据) {
                    String s = "组装的信息" + "\r\n";
                    buff = s.getBytes();
                    o = new FileOutputStream(file, true);
                    o.write(buff);
                    o.flush();
                    o.close();
                }
                System.out.println("写数据成功!");
            } catch (IOException | ParseException e) {
                e.printStackTrace();
            }

 

posted @ 2023-02-06 17:23  程序员hg  阅读(522)  评论(0编辑  收藏  举报