源码:
import java.io.*;
class inread{
public static void mian(String args[])
{
FileInputStream fis = new FileInputStream("c:\s.txt");
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
System.out.println(s);
br.close();
}
}
错在哪啊
--------------------Configuration: <Default>--------------------
C:\inread.java:5: illegal escape character
                FileInputStream fis = new FileInputStream("c:\\s.txt");
                                                              ^
1 errorProcess completed.

解决方案 »

  1.   

    试一下下面的代码,增加异常的抛出
    import java.io.*;
    public class inread{
    public static void main(String args[]) throws IOException
    {
    FileInputStream fis = new FileInputStream("c:/s.txt");
    InputStreamReader isr = new InputStreamReader(fis);
    BufferedReader br = new BufferedReader(isr);
    String s = br.readLine();
    System.out.println(s);
    br.close();
    }
    }
      

  2.   

    增加异常的抛出
    二是文件中\要用转议符
    应该写成C:\\s.txt
      

  3.   

    你想读几行就执行多少次readline嘛。不过最好要加个判断。也可以使用读字节的。
      

  4.   

    用while(in.readLine()!=null){ String s = in.readLine()}
      

  5.   

    import java.io.*;public class Inread{
    public static void main(String args[])
     {
      try{
        //FileInputStream fis = new FileInputStream("c:\\s.txt");
        //InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader br = new BufferedReader(
                                 new InputStreamReader(
                                      new FileInputStream("c:\\s.txt")));
        String s;
        while((s=br.readLine())!=null)
        System.out.println(s);
        br.close();
        }catch(IOException e){e.printStackTrace();}
     }
    }
      

  6.   

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
       String s;
       while((s = br.readLine()) != null) //null即是ctrl+z而不是空格.
        System.out.println(s);
       }catch(IOException e){
       e.printStackTrace(System.err);
      }finally{
       br.close();
      }
      

  7.   

    BufferedReader br = new BufferedReader(
                                 new InputStreamReader(
                                      new FileInputStream("c:\\s.txt")));
    这样写简单多了。
    还有你的main好像写成mian了
      

  8.   

    同意
    dogod(那天,正喝着汤,猛然间....睡着了!) 
      

  9.   

    dogod(那天,正喝着汤,猛然间....睡着了!) 
      写的比较规范