/**
* 向文件末尾添加字符串
* jdk 1.7 新增 try - with - resource
* 无需finally自动释放资源
* @author rgy
*
*/
public class AppendStrDemo {
public void append(String path){
try(PrintWriter printWriter = new PrintWriter(new BufferedWriter(new FileWriter(path, true), 1024))){
printWriter.write("hello world!");
}catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
AppendStrDemo apdStrDemo = new AppendStrDemo();
apdStrDemo.append("src/t.txt");
}
}
向文件末尾添加字符串
最新推荐文章于 2019-06-19 10:03:00 发布