📄 filerecord.java
字号:
package generalSort;
import java.io.PrintWriter;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
/**
* <p>Title: FileRecord</p>
*
* <p>Description:A class for operating the file, which has two methods
****Method void append_tofile(String content) appends 'content' to the end of the file "C:\\GeneralSort_Report.doc"
****Method boolean openfile() opens the file "C:\\GeneralSort_Report.doc"
* </p>
* <p>Copyright: Copyright (c) 2008 All rights reserved</p>
* <p>Organization :Shandong University </p>
* @Email:ruohanxiao@yahoo.com.cn
* @author: Xiao Ruohan
* @version 1.0
*/
public class FileRecord {
private static String file_name = "C:\\GeneralSort_Report.doc";
private String changedString = "";
private File f = new File(file_name);
private FileWriter fw = null;
private PrintWriter pw = null;
private String analysis_content =
"<-----------------------GeneralSort Report--------------------------->";
public FileRecord() {
this.append_tofile(this.analysis_content);
}
public FileRecord(String fname) {
file_name = fname;
}
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 + -