?? readfile.java
字號:
package com.chapter4;
import java.io.*;
import java.util.StringTokenizer;
public class ReadFile
{
//類成員變量
private String currentRecord;
private BufferedReader file;
private String path;
private StringTokenizer token;
//建立文件對象
public int createFileObj(String filePath)
{
int i = 0;
path = filePath;
try
{
file = new BufferedReader(new FileReader(path));
}
catch (FileNotFoundException e)
{
i = -1;
}
return i;
}
//得到文件路徑
public String getPath()
{
return path;
}
//讀取下一行記錄,若沒有則返回-1
public int nextRecord()
{
int i = -1;
try
{
currentRecord = file.readLine();
}
catch (IOException e)
{
System.out.println("讀取文件內容失??!");
}
if (currentRecord == null)
{
i = -1;
}
else
{
token = new StringTokenizer(currentRecord);
i = token.countTokens();
}
return i;
}
//以字符串的形式返回某行數據
public String returnRecord()
{
return currentRecord;
}
//關閉文件流
public void close() throws IOException
{
file.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -