You can easily write data to HDFS using the hadoop public library (if you use sbt as a dependency configuration tool, add this library to your dependency). With this, you can create a FileSystem object :
private val fs = {
val conf = new Configuration()
FileSystem.get(conf)
}
(core-site.xml ..)
, , String to path ( ), HDFS, :
@throws[IOException]
def writeAsString(hdfsPath: String, content: String) {
val path: Path = new Path(hdfsPath)
if (fs.exists(path)) {
fs.delete(path, true)
}
val dataOutputStream: FSDataOutputStream = fs.create(path)
val bw: BufferedWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream, "UTF-8"))
bw.write(content)
bw.close
}