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

无法使用scala将字符串写入hdfs文件,scala,file,hdfs,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(

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

代码工作正常。这取决于你是如何调用write函数的。你能给我更多的细节吗?你必须给出你是如何访问write函数的细节。