public void test() throws IOException{
File f=new File("d:"+File.separator+"1.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(f)));
StringBuffer whole=new StringBuffer();
String line=new String();
for (line=br.readLine(); line!=null; line=br.readLine()) {
whole.append(line);
}
System.out.println(whole.toString());
}
使用readLine()對(duì)整個(gè)文件或者Read流進(jìn)行字符掃描
public void test1() throws IOException{
File f=new File("d:"+File.separator+"1.txt");
BufferedInputStream br=new BufferedInputStream(new FileInputStream(f));
StringBuffer whole=new StringBuffer();
int line;
for (line=br.read(); line!=-1; line=br.read()) {
whole.append(line);
}
System.out.println(whole.toString());
}
使用read()對(duì)整個(gè)文件或者Read流進(jìn)行字節(jié)的掃描