0
我是全新的,以问问题在这里,很抱歉,如果我这样做是错误的。 我想追加一个完整的.txt文件到另一个结尾,在一个新行,而不重写内容。
例如,我有这个在此时就把one.txt存盘
TEST 1 00001 BCOM
,我有这two.txt,
TEST 2 00001 BCOM
这是唯一的工作代码,我发现将复制/覆盖到另一个文件, 所有其他我复制,重写文件路径和名称,并试过,它不适用于我。我仍然是Java的初学者。
import java.io.*;
class CompileData {
public static void main(String args[]) {
FileReader fr = null;
FileWriter fw = null;
try {
fr = new FileReader("one.txt");
fw = new FileWriter("two.txt");
int c = fr.read();
while(c!=-1) {
fw.write(c);
c = fr.read();
}
} catch(IOException e) {
e.printStackTrace();
} finally {
close(fr);
close(fw);
}
}
public static void close(Closeable stream) {
try {
if (stream != null) {
stream.close();
}
} catch(IOException e) {
}
}
}
有了这个代码,而不是让这对two.txt
TEST 1 00001 BCOM
TEST 2 00002 BCOM
我只得到了two.txt
TEST 1 00001 BCOM
任何帮助,技巧,三分球和答案将是欣赏!