源码:
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.
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.
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();
}
}
二是文件中\要用转议符
应该写成C:\\s.txt
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();}
}
}
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();
}
new InputStreamReader(
new FileInputStream("c:\\s.txt")));
这样写简单多了。
还有你的main好像写成mian了
dogod(那天,正喝着汤,猛然间....睡着了!)
写的比较规范