appendfile.java
来自「《jsp网站开发技术》中的源代码(清华大学出版社)」· Java 代码 · 共 43 行
JAVA
43 行
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 + =
减小字号Ctrl + -
显示快捷键?