?? filereader.java
字號:
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* This class contains utility methods to read board position from the input file.
* @author sanshack
*
*/
public class FileReader {
/**
* This method reads the position given in the filename.
* @param filename - input filename
* @return board position in the filename
*/
public String getPosition(String filename) {
File file = new File(filename);
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
String message = null;
try {
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
///////////////////////////////////////////////////////////////
message = dis.readLine();
if(message.length()!=23)System.out.println("Invalid Board Position");
dis.close();
bis.close();
fis.close();
}catch (FileNotFoundException f) {
System.out.println(filename+" is not found");
}catch(IOException i) {
System.out.println("Could not read from "+filename);
}
return message;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -