?? readfile.java
字號(hào):
package file;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
//讀取文件類
public class ReadFile {
private String pathname; // 文件路徑
// 構(gòu)造方法
// pathname 文件路徑
public ReadFile(String pathname) {
this.pathname = pathname;
}
public String getPathname() {
return pathname;
}
public void setPathname(String pathname) {
this.pathname = pathname;
}
// 讀取文件 失敗拋出異常IOException
public String read() throws IOException {
File file = new File(pathname); // 建立文件類
int len = 0; // 用于記錄文件長(zhǎng)度
FileReader fileReader = new FileReader(new File(pathname)); // 建立讀取字符文件類
len = (int) file.length(); // 獲取并記錄文件長(zhǎng)度
char[] temp = new char[len]; // 用于存儲(chǔ)文件字符流
fileReader.read(temp, 0, len); // 從文件讀入字符流
return new String(temp, 0, len); // 記錄字符流并返回
}
// 返回文件名
public String getFileName() {
return pathname.substring(pathname.lastIndexOf('\\') + 1); // 從刪除地址中'\'之前的字符
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -