FileSystem fs = FileSystem.get(conf);
Path file = new Path("hdfs://localhost:9000/wordcount/data/word.txt");
FSDataInputStream inStream = fs.open(file);
BufferedReader bf=new BufferedReader(new InputStreamReader(inStream));//防止中文乱码
String line = null;

while ((line = bf.readLine()) != null) {

}

如果没有红色部分,将bf.readLine()改为inStream.readLine(),中文就会乱码

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐