public static void main(String[] args){
File file2=new File(args[0]);
try{
BufferedReader ar=new BufferedReader(new FileReader(file2));

String s;
while((s=ar.readLine())!=null){
System.out.println(s);
    }
ar.close();
}catch(IOException e){
}
         }
////////////////////////////////////////////
public static void main(String[] args){
File file2=new File(args[0]);
try{
BufferedReader ar=new BufferedReader(new FileReader(file2));

String s="";
while(ar.read()!=-1){
s+=(char)ar.read();
    }
System.out.println(s);
ar.close();
}catch(IOException e){
}
         }
为什么两个读出来的都不同呢

解决方案 »

  1.   

    Class BufferedReaderint read() 
              Read a single character. 
    Returns:
    The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached .String readLine() 
              Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns:
    A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached .