BufferedReader.readLine() 切断行的开头

发布于 2024-11-28 05:55:44 字数 897 浏览 1 评论 0原文

我在读取文件时遇到问题。

BufferedReader in = new BufferedReader(
                      new InputStreamReader(
                         new FileInputStream(file), "UTF-8"));
while ((line = in.readLine()) != null) {
   parseLine(line);
}

Trouble causing line:
 a:38:{s:10:"aaaaaaaaaa";s:6:"215302";s:4:"bbbb";s:9:"新村莊";s:10:"cccccccccc";s:6:"330345";s:6:"dddddd";s:3:"-68";s:6:"eeeeee";s:3:"-12";s:9:"fffffffff";s:4:"3470";s:7:"ggggggg";s:1:"3";s:10:"hhhhhhhhhh";s:1:"2";s:7:"iiiiiii";s:3:"391";s:11:"jjjjjjjjjjj";s:1:"2";s:15:"jjjjjjjjjjjjjjj";s:1:"8";s:15:"jjjjjjjjjjjjjjj";s:1:"8";s:15:"jjjjjjjjjjjjjjj";s:1:"8";s:16:"jjjjjjjjjjjjjjjj";s:2:"12";s:14:"jjjjjjjjjjjjjj";N;s:11:"jjjjjjjjjjj";N;s:13:"jjjjjjjjjjjjj";N;s:20:"jjjjjjjjjjjjjjjjjjjj";s:1:"1"... etc

在大约第 105000 行中的第 30 个文件处,readline() 截断了前 69 个字符。该行共有 936 个字符。

知道为什么 readline() 会截断字符吗? (顺便说一句,有些线路更长!)

I have a problem with reading a file.

BufferedReader in = new BufferedReader(
                      new InputStreamReader(
                         new FileInputStream(file), "UTF-8"));
while ((line = in.readLine()) != null) {
   parseLine(line);
}

Trouble causing line:
 a:38:{s:10:"aaaaaaaaaa";s:6:"215302";s:4:"bbbb";s:9:"新村莊";s:10:"cccccccccc";s:6:"330345";s:6:"dddddd";s:3:"-68";s:6:"eeeeee";s:3:"-12";s:9:"fffffffff";s:4:"3470";s:7:"ggggggg";s:1:"3";s:10:"hhhhhhhhhh";s:1:"2";s:7:"iiiiiii";s:3:"391";s:11:"jjjjjjjjjjj";s:1:"2";s:15:"jjjjjjjjjjjjjjj";s:1:"8";s:15:"jjjjjjjjjjjjjjj";s:1:"8";s:15:"jjjjjjjjjjjjjjj";s:1:"8";s:16:"jjjjjjjjjjjjjjjj";s:2:"12";s:14:"jjjjjjjjjjjjjj";N;s:11:"jjjjjjjjjjj";N;s:13:"jjjjjjjjjjjjj";N;s:20:"jjjjjjjjjjjjjjjjjjjj";s:1:"1"... etc

At about the 30th file in row about 105000, readline() cuts off the first 69 characters. The line has a total of 936 characters.

Any idea why readline() cuts off the characters? (BTW, there are lines that are longer!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失退 2024-12-05 05:55:44

我尝试了您的代码,但使用了一个简单的 System.out.println(line) ,您在其中调用了 parseLine(line) 方法,并且一切正常:导致问题的示例行在我的控制台中显示正确。

请自己尝试一下,让我们看看您的 parseLine(line) 方法。

I tried your code but with a simple System.out.println(line) where you call the parseLine(line) method and everything works fine: your sample trouble causing line appears correct in my console.

Please try yourself and let us see your parseLine(line) method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文