package collection;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class Demo1 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) {
FileWriter fw = null;
try {
fw = new FileWriter("f:\\demo.txt",true);//IO流文件续写
fw.write("\r\nasfdfgvagves");
fw.flush();
} catch (IOException e) {
System.out.println(e.toString());
}
finally{
try {
if(fw!=null)
fw.close();
} catch (IOException e) {
System.out.println(e.toString());
}
}
}
private static void sop(Object string) {
System.out.println(string);
}
}
本文提供了一个使用Java进行文件续写的示例代码,通过FileWriter实现对指定路径下的文件进行追加写入操作,并展示了如何捕获并处理可能出现的IOException。
526

被折叠的 条评论
为什么被折叠?



