![](https://i-blog.csdnimg.cn/blog_migrate/859ec2a8347e1dc719ccaf293af23264.png)
在使用IDEA中使用 FSDataOutputStream.writeUTF(String) 向hdfs中写文件时,如果把文件下载到本地,打开会看到如上图一样类似的乱码或有空行的情况,代码如下:
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
// 获得文件系统
Configuration configuration = new Configuration();
// 配置在集群上运行
FileSystem fs = FileSystem.get(new URI("hdfs://hadoop101:9000"), configuration, "ml");
if (fs.exists(new Path("/xxy/Demo01/hdfs/test.csv"))) {
fs.delete(new Path("/xxy/Demo01/hdfs/test.csv"));
}
FSDataOutputStream fos = fs.create(new Path("/xxy/Demo01/hdfs/test.csv"));
HashMap<String, Double&
|