如题所述
File file=new File("f:/a.txt");
BufferedWriter bw=null;
try {
bw=new BufferedWriter(new FileWriter(file,true));
bw.write("efg");
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这里关键代码bw=new BufferedWriter(new FileWriter(file,true));
后面参数的true,就代表即使a.txt里面有内容,也不会替换。
BufferedWriter bw=null;
try {
bw=new BufferedWriter(new FileWriter(file,true));
bw.write("efg");
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这里关键代码bw=new BufferedWriter(new FileWriter(file,true));
后面参数的true,就代表即使a.txt里面有内容,也不会替换。
温馨提示:答案为网友推荐,仅供参考
第1个回答 2011-12-13
/**
* @param args
*/
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = null;
PrintWriter printWriter = null;
try{
bufferedReader = new BufferedReader(new FileReader("text1.txt"));
printWriter = new PrintWriter(new FileWriter("text.txt", true));
String l;
while ((l = bufferedReader.readLine()) != null) {
printWriter.print(l);
}
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
if (printWriter != null) {
printWriter.close();
}
}
}
希望对你有所帮助本回答被提问者采纳
* @param args
*/
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = null;
PrintWriter printWriter = null;
try{
bufferedReader = new BufferedReader(new FileReader("text1.txt"));
printWriter = new PrintWriter(new FileWriter("text.txt", true));
String l;
while ((l = bufferedReader.readLine()) != null) {
printWriter.print(l);
}
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
if (printWriter != null) {
printWriter.close();
}
}
}
希望对你有所帮助本回答被提问者采纳
第2个回答 2011-12-13
FileOutputStream(File file, boolean append)
Creates a file output stream to write to the file represented by the specified File object.
Creates a file output stream to write to the file represented by the specified File object.