io问题

leonard_sun 2006-01-23 01:39:49
源码:
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 error

Process completed.
...全文
189 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenlong1045 2006-03-22
  • 打赏
  • 举报
回复
dogod(那天,正喝着汤,猛然间....睡着了!)
写的比较规范
hellosjz 2006-03-21
  • 打赏
  • 举报
回复
多读几行可以加个控制,这样就OK了
aywrenyue 2006-03-09
  • 打赏
  • 举报
回复
同意
dogod(那天,正喝着汤,猛然间....睡着了!)
已经存在 2006-03-09
  • 打赏
  • 举报
回复
BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream("c:\\s.txt")));
这样写简单多了。
还有你的main好像写成mian了
lyf040230427 2006-03-08
  • 打赏
  • 举报
回复
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();
}

dogod 2006-03-08
  • 打赏
  • 举报
回复
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();}
}
}
做鸡真好吃 2006-03-06
  • 打赏
  • 举报
回复
???????????
yonghar 2006-01-24
  • 打赏
  • 举报
回复
你想读几行就执行多少次readline嘛。不过最好要加个判断。

也可以使用读字节的。
pengpenglin 2006-01-24
  • 打赏
  • 举报
回复
用while(in.readLine()!=null){ String s = in.readLine()}
denny008 2006-01-23
  • 打赏
  • 举报
回复
可以了,但是只能读一行怎么实现连续读几行啊
725137 2006-01-23
  • 打赏
  • 举报
回复
增加异常的抛出
二是文件中\要用转议符
应该写成C:\\s.txt
jragon 2006-01-23
  • 打赏
  • 举报
回复
试一下下面的代码,增加异常的抛出
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();
}
}

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧