夜半歌声丶 2017-11-24 13:44 采纳率: 100%
浏览 693
已采纳

ava 将读入的文件的一段截取下来并保存时出现nullpointerexception [

public String[] read()
{
try {
String path="data.txt";
File f=new File(path);
InputStreamReader reader= new InputStreamReader(new FileInputStream(f));
BufferedReader br=new BufferedReader(reader);
String line="";
String[] s=new String[36801];
int n=0;
line=br.readLine();
while(line!=null)
{

line=br.readLine();
s[n]=line.substring(41,45);
System.out.print(s[n]+" ");
n++;
}
br.close();
return s;
}catch (IOException e) {
e.printStackTrace();
}
return null;
}
下面读的文件 中的其中一行2011:08:03:00:00:05:687: C1 1273 60001 1277 2947 6625 3 6 1277 1269 1272 1348 1375 1182 0 0 0 0

  • 写回答

2条回答 默认 最新

  • 天之上有什么 2017-11-25 05:11
    关注

    while循环里的line=br.readline;这句由于已经执行过一次,再执行就会返回null,所以while循环里的line为null,程序需要用到null对象时发现为空,所以抛出nullpointerexception异常

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记