我编写了一些代码来在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
检查文件内容时,我看不到任何内容?