Scala DataStream API: Write String Elements to File
import org.apache.flink.streaming.api.scala._ import java.io.{File, PrintWriter}
val env = StreamExecutionEnvironment.getExecutionEnvironment val strStream = env.fromElements('hadoop is powerful', 'spark is fast', 'flink is better')
strStream.writeUsingOutputFormat(new TextOutputFormatString { override def getOutputFilePath: String = "/home/hadoop/output.txt" override def writeRecord(record: String): Unit = { val writer = new PrintWriter(new File(getOutputFilePath), true) writer.write(record + "\n") writer.close() } })
env.execute('Write to file')
原文地址: https://www.cveoy.top/t/topic/ozji 著作权归作者所有。请勿转载和采集!