无法使用scala将字符串写入hdfs文件

时间:2018-04-20 08:51:12

标签: scala file hdfs

我编写了一些代码来在hdfs中创建一个文件并向其写入字节。这是代码:

def write(uri: String, filePath: String, data: String): Unit = {
    System.setProperty("HADOOP_USER_NAME", "hibou")
    val path = new Path(filePath + "/hello.txt")
    val conf = new Configuration()
    conf.set("fs.defaultFS", uri)
    val fs = FileSystem.get(conf)
    val os = fs.create(path)
    os.writeBytes(data)
    os.flush()
    fs.close()
  }

代码成功没有错误,但我只看到该文件已创建。当我使用hdfs -dfs -cat /.../hello.txt检查文件内容时,我看不到任何内容?

0 个答案:

没有答案
相关问题