我使用 fileStream 从 Spark(流上下文)读取 hdfs 目录中的文件。如果我的 Spark 关闭并在一段时间后启动,我想读取目录中的新文件。我不想读取目录中已被 Spark 读取和处理的旧文件。我在这里尽量避免重复。
val lines = ssc.fileStream[LongWritable, Text, TextInputFormat]("/home/File")
有什么代码片段可以提供帮助吗?
最佳答案
您可以使用 FileSystem
API:
import org.apache.hadoop.fs.{FileSystem, Path}
val fs = FileSystem.get(sc.hadoopConfiguration)
val outPutPath = new Path("/abc")
if (fs.exists(outPutPath))
fs.delete(outPutPath, true)
关于scala - 使用scala读取后如何删除hdfs目录中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45104284/