IOException

求解决办法!! 将数据传入hdfs上报错:java.io.IOException: Path: //linux01 is a directory, which is not supported by the record reader when mapreduce.input.fileinputformat.input.dir.recursive is false.


```scala
object Test {
  def main(args: Array[String]): Unit = {
    val sc = new SparkContext(new SparkConf().setMaster("local").setAppName("aa"))

    sc.textFile("hdfs://linux01:8020/data/wc").flatMap(_.split(" ")).map((_,1)).saveAsTextFile("hdfs://linux01:8020/data/wc/out3")
  }
}


```

img

这个错误是因为 mapreduce.input.fileinputformat.input.dir.recursive 属性被设置为 false,导致不能支持处理目录。可以尝试设置该属性为 true,或者修改输入路径为文件路径而不是目录路径。具体操作如下:

  1. 设置 mapreduce.input.fileinputformat.input.dir.recursive 为 true。
val conf = new Configuration()
conf.set("mapreduce.input.fileinputformat.input.dir.recursive", "true")
val sc = new SparkContext(new SparkConf().setMaster("local").setAppName("aa").set("spark.hadoop.fs.defaultFS", "hdfs://linux01:8020").set("spark.hadoop.rpc.address", "localhost"), conf)
  1. 修改输入路径为文件路径。

将输入路径修改为文件路径,即直接指定具体的输入文件。例如,将 hdfs://linux01:8020/data/wc 修改为 hdfs://linux01:8020/data/wc/input.txt

sc.textFile("hdfs://linux01:8020/data/wc/input.txt").flatMap(_.split(" ")).map((_,1)).saveAsTextFile("hdfs://linux01:8020/data/wc/out3")