java文件写入不覆盖:Java文件的重要性

使用类的append()方法可以实现文件写入不覆盖的功能,下面是一个示例代码:import java.io.*;

使用类的append()方法可以实现文件写入不覆盖的功能,是一个示例代码:import java.io.*;

使用FileWriter类的append()方法可以实现文件写入不覆盖的功能,是一个示例代码:

import java.io.*;

public class AppendToFileExample {

public static void main(String[] args) {

try {

String content = "This is my content which would be appended at the end of the file";

File file = new File("example.txt");

// if file doesnt exists, then create it

if (!file.exists()) {

file.createNewFile();

}

// true = append file

FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);

BufferedWriter bw = new BufferedWriter(fw);

bw.write(content);

bw.close();

System.out.println("Done");

} catch (IOException e) {

e.printStackTrace();

}

}

}

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(124)
java回合制游戏一场java回合制游戏的冒险之旅
上一篇
java 消息中心:如何利用Java消息中心实现高效的消息传递
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(23条)