private String readFile(String filePath, BufferedReader reader) throws FileNotFoundException, IOException { codeString = null; int i = 0; FileInputStream fis = new FileInputStream(filePath); if (reader == null) reader = new BufferedReader(new InputStreamReader(fis)); String line = reader.readLine(); while (line != null){ line = reader.readLine(); } return codeString; }这样就可以了,然后可以调用并返回读入的数据 调用函数的时候记得try就行了
楼上的有少少笔误。 while (line != null){ line = reader.readLine(); // codeString = reader.readLine(); }
private String readFile(String filePath, BufferedReader reader) throws FileNotFoundException, IOException { codeString = null; int i = 0; FileInputStream fis = new FileInputStream(filePath); if (reader == null) reader = new BufferedReader(new InputStreamReader(fis)); String line = reader.readLine(); while (line != null){ line = reader.readLine(); } return codeString; }这样就可以了,然后可以调用并返回读入的数据 调用函数的时候记得try就行了
int data = new DataInputStream(new FileInputStream("aaa.txt")).readInt();不是很方便吗,又不是读一行。
int data = new DataInputStream(new FileInputStream("aaa.txt")).readInt(); //相当于 FileInputStream fin = new FileInputStream("aaa.txt"); DataInputStream din = new DataInputStream(fin); int data = din.readInt();
throws FileNotFoundException, IOException {
codeString = null;
int i = 0;
FileInputStream fis = new FileInputStream(filePath);
if (reader == null)
reader = new BufferedReader(new InputStreamReader(fis));
String line = reader.readLine();
while (line != null){
line = reader.readLine();
}
return codeString;
}这样就可以了,然后可以调用并返回读入的数据
调用函数的时候记得try就行了
line = reader.readLine(); // codeString = reader.readLine();
}
throws FileNotFoundException, IOException {
codeString = null;
int i = 0;
FileInputStream fis = new FileInputStream(filePath);
if (reader == null)
reader = new BufferedReader(new InputStreamReader(fis));
String line = reader.readLine();
while (line != null){
line = reader.readLine();
}
return codeString;
}这样就可以了,然后可以调用并返回读入的数据
调用函数的时候记得try就行了
//相当于
FileInputStream fin = new FileInputStream("aaa.txt");
DataInputStream din = new DataInputStream(fin);
int data = din.readInt();