import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;public class File4 {
/**
 * @param args
 * @throws IOException 
 */
public static void main(String[] args) throws IOException {
// TODO 自动生成方法存根
BufferedReader br=new BufferedReader(new FileReader("file1.txt"));
String str=br.readLine();
System.out.println(str);
br.close();
}
}我的 file1.txt中有好多行数据,现在要按行读出,而BufferedReader.readLine()只可以读取一行啊,那该怎么办?。。谢谢!

解决方案 »

  1.   

    加个循环啊
    import java.io.BufferedReader; 
    import java.io.FileReader; 
    import java.io.IOException; public class File4 { 
    /** 
     * @param args 
     * @throws IOException  
     */ 
    public static void main(String[] args) throws IOException { 
    // TODO 自动生成方法存根 
    BufferedReader br=new BufferedReader(new FileReader("file1.txt")); 
    String str;
    while(str=br.readLine()!=null); 
    {System.out.println(str); 
    }
    br.close(); 


      

  2.   

    晕了,又有问题了,刚刚我这个程序改后在dos控制台下javac ,java后可以顺利运行,但现在我放倒eclipse中编译不过!提示 类型(string 和 null(boolean))不匹配啊!.......  就这里while(str=br.readLine()!=null);
      

  3.   

    while(str=br.readLine()!=-1);这样看看~`
      

  4.   

    这样更不行啊,-1可是int型啊!
    还有高手不?
      

  5.   

    哦~我看错了~不好意思~我也是你那样用啊没错~while((str=br.readLine())!=null);
      

  6.   


    public static void main(String args[]) throws IOException {
    BufferedReader br = null;
    try {
    br = new BufferedReader(new FileReader("file1.txt"));
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }  
    String str; 
    try {
    while((str = br.readLine()) != null) {
    System.out.println();  
    }
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

    br.close();   }这个没编译,不过我觉得这个应该对,你试下
      

  7.   

    已解决,少了一个括号:
    while((str=br.readLine())!=null);
    while(str=br.readLine()!=null);
    不一样的!太不小心了!。结帖!