按行读取文件内容的错误?

bbshero 2003-10-20 10:43:19
String sline="";
File file = new File("c:\\ini.txt");
FileInputStream fins=null;
BufferedInputStream bins=null;
DataInputStream dins=null;//--------------------


fins = new FileInputStream(file);
bins = new BufferedInputStream(fins);
dins = new DataInputStream(dins);
try{
while( (sline = dins.readLine()).length() != 0 )
out.print(sline); }
catch(Exception e) {e.printStackTrace();out.print("readall failure失败");}
out.print("-------------end-------------");



总报告说java.lang.NullPointer
...全文
32 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pisalin 2003-10-20
  • 打赏
  • 举报
回复
试试这样
String sline="";
File f = new File("c:\\ini.txt");
InputStreamReader read = new InputStreamReader (new FileInputStream(f));
BufferedReader dins = new BufferedReader(read);
try{
while( (sline = dins.readLine()).length() != 0 )
out.print(sline); }
catch(Exception e) {e.printStackTrace();out.print("readall failure失败");}
out.print("-------------end-------------");
bbshero 2003-10-20
  • 打赏
  • 举报
回复
该成(bins)也失败啊!
pisalin 2003-10-20
  • 打赏
  • 举报
回复
dins = new DataInputStream(dins);//???
笔误?应该是:dins = new DataInputStream(bins);
bbshero 2003-10-20
  • 打赏
  • 举报
回复
谢谢 pisalin(创新思维) 给分
不过我的为什么不对?

81,091

社区成员

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

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