BufferedReader.readLine()切断了行的开头

时间:2011-08-05 13:14:40

标签: java readline bufferedreader

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

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()切断角色的原因吗? (顺便说一下,有些线条更长!)

1 个答案:

答案 0 :(得分:0)

我尝试了你的代码,但是使用一个简单的System.out.println(line)来调用parseLine(line)方法,一切正常:你的样本故障导致行在我的控制台中显示正确。

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