?? appendfile.java
字號:
package appendfile;
import java.io.*;
public class AppendFile {
private String path;
private String something;//追加的字符串變量
//構造函數
public AppendFile() {
path = null;
something = "Default message";
}
//設置文件路徑
public void setPath(String apath) {
path = apath;
}
//得到文件路徑
public String getPath() {
return path;
}
//設置要追加的字符串
public void setSomething(String asomething) {
something = asomething;
}
//得到要追加的字符串
public String getSomething() {
return something;
}
//追加字符串
public String writeSomething() {
try {
//創建文件path并寫入something字符串,注意和寫入篇的區別
FileWriter theFile = new FileWriter(path,true);
PrintWriter out = new PrintWriter(theFile);
out.print(something + "\n");
out.close();
//關閉文件并返回success字符串
theFile.close();
return "success!!";
} catch (IOException e) {
return e.toString();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
增大字號
Ctrl + =
減小字號
Ctrl + -