測试样例: Java读取UTF-8的txt文件第一行出现乱码"?"及解决 test.txt文件内容: 1 00:00:06,000 --> 00:00:06,010 <b>Allerleirauh</b> (2012) <i>dTV - Das Erste - 20. Januar 2013</i> 2 00:00:10,280 --> 00:00:12,680 Was geh?rt zu einer guten Suppe?
with open(file,'r') as f: line=f.readline() i=1 while line: line=line.decode('utf-8') line=f.readline() i=i+1 用以上代码读取一个包含中文的txt文件时,在正确地读取并打印了六百多行之后,print str(i)+": "+line这一行报错: UnicodeEncodeError: 'gbk' codec can't encode character u'\u200b' in