-2
是否可以在不覆蓋以前的數據的情況下將文本寫入文件?輸出不覆蓋
我一直做的是:
StringBuffer sb = new StringBuffer();
BufferedReader in;
PrintWriter out;
try{
in = new BufferedReader(new FileReader("somefile.txt"));
out = new PrintWriter(new FileWriter("somefile.txt"));
String input = "";
while(input != null){
sb.append(input + "\n");
input = in.readLine();
}
in.close()
out.print(sb.toString());
// now start doing what I want.
這是正確的方法是什麼?