/**
* 向檔案末尾添加字元串
* 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), ))){
printWriter.write("hello world!");
}catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
AppendStrDemo apdStrDemo = new AppendStrDemo();
apdStrDemo.append("src/t.txt");
}
}