向文件末尾添加字符串

来源:互联网 发布:淘宝网不能正常打开 编辑:程序博客网 时间:2024/06/05 01:59
/** * 向文件末尾添加字符串 * 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");    }}
0 0