filreader 中的 java 子字符串 while
找不到有关如何执行此操作的任何帮助: 我无法在 Filreader 中使用 .substring,它在读取第一行后会引发异常。
String line = "";
BufferedReader in = new BufferedReader( new FileReader(f) );
LineNumberReader lnr = new LineNumberReader(in);
while ((line = lnr.readLine()) != null) {
System.out.println(lnr.getLineNumber() + " : " + line.substring(1, 7) +"!");
}
in.close();
lnr.close();
Can't find any help on how to do this:
I can't use .substring in the Filreader's while, it throws an exception after reading the first line.
String line = "";
BufferedReader in = new BufferedReader( new FileReader(f) );
LineNumberReader lnr = new LineNumberReader(in);
while ((line = lnr.readLine()) != null) {
System.out.println(lnr.getLineNumber() + " : " + line.substring(1, 7) +"!");
}
in.close();
lnr.close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很高兴您已经找到问题的答案,另外我想建议在调用子字符串时添加范围检查(至少在需要可变长度行的情况下)
Glad that you have already found the answer to your problem, additionally I would like to suggest adding a range check when calling substring (at least in cases where a variable length of line is expected)