我有一个字符串,我想覆盖它并在Scala中编写一个hdfs文本文件。下面是我当前正在使用的代码。
import java.io.{BufferedOutputStream, FileOutputStream}
val fs = FileSystem.get(sc.hadoopConfiguration);
val filename = "hdfs://<IP>:9000/path/to/save/mytext.conf"
val textout = fs.create(new Path(filename));
val value1 = 23
val value2 = 25
val os = java.io.BufferedOutputStream(textout)
os.write(("key1: " + value1 + "\n").getBytes("UTF-8"))
os.write(("key2: " + value2 + "\n").getBytes("UTF-8"))
os.close()
不幸的是,上面的代码给了我以下错误:
<console>:146: error: object java.io.BufferedOutputStream is not a value
val os = java.io.BufferedOutputStream(textout)
^
如何在Scala的HDFS中将键值对保存在文本文件中?
答案 0 :(得分:0)
visibility off