java中用utf8如何读取txt文件第二行内容,并在屏幕输出!

public void readTxtFile(String filePath){
try {
File f = new File(filePath);
if(f.isFile()&&f.exists()){
InputStreamReader isr = new InputStreamReader(new FileInputStream(f),"utf-8");
BufferedReader br = new BufferedReader(isr);
String lineTxt = null;
int a = 0;
while((lineTxt=br.readLine())!=null){
a++;
if(a==2){
break;
}
}
System.out.println(lineTxt);
br.close();
isr.close();
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

输出lineTxt一直乱码,求大神帮忙!

调用两次 readLine() 就是了。。。。。。。。。。 乱码和命令行的编码有关,,重新写入另一文件看看是不是真正utf-8的
温馨提示:答案为网友推荐,仅供参考
相似回答