是否可以在不覆盖以前数据的情况下将文本写入文件?
我一直在做的是:
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.
这是正确的方法吗?