📄 filerecord.java~6~
字号:
package generalSort;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FileRecord {
static String file_name = "C:\\Analysis_Report.doc";
String changedString = "";
File f = new File(file_name);
FileWriter fw = null;
PrintWriter pw = null;
String analysis_content =
"<-----------------------Analysis Report--------------------------->";
public FileRecord() {
}
public void append_tofile(String content) {
try {
if (!f.exists()) { //检查文件是否存在
f.createNewFile(); //删除文件
}
fw = new FileWriter(f, true); //建立FileWriter对象,并实例化fw
//将字符串写入文件
pw = new PrintWriter(fw);
changedString = content.replaceAll("\n",
System.getProperty(
"line.separator")); //将换行符转换为系统默认的换行符
pw.println(changedString);
pw.close();
fw.close();
} catch (IOException ex) {
}
}
public boolean open_file() {
try {
Runtime.getRuntime().exec(
"cmd.exe /c start " + file_name); //打开文件记录
return true;
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Fail to open the file"+file_name);
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -