完整例子如下
package net
import java
import java
import java
public class ReadFile {
private String path;
public ReadFile(String filePath){
path = filePath;
}
public String[] openFile() throws IOException{
FileReader fr = new FileReader(path)
BufferedReader textReader = new BufferedReader(fr)
String[] textData = new String[readLines()];
int i;
for(i=
textData[i] = textReader
}
textReader
return textData;
}
int readLines() throws IOException{
FileReader fileToRead = new FileReader(path)
BufferedReader bf = new BufferedReader(fileToRead)
int numberOfLines =
@SuppressWarnings(
String oneLine;
while((oneLine = bf
numberOfLines++;
}
bf
return numberOfLines;
}
}
package net
import java
public class FileData {
public static void main(String[] args) throws IOException{
String filePath =
try{
ReadFile reader = new ReadFile(filePath)
String[] content = reader
int i;
for(i=
System
}
}catch(IOException e){
System
}
}
}
java
The buffer size may be specified
In general
BufferedReader in = new BufferedReader(new FileReader(
Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader
java
FileReader is meant for reading streams of characters
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26249.html