📄 b0b1d0c24efb001c1573b62be8af1246
字号:
package com.sans.ninemen.io;
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();
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -