在idea中通过spark读取文件是报的错误
Exception in thread "main" java.lang.IllegalArgumentException: Pathname /C:/Users/slm/Desktop/tuijian.txt from hdfs://slm001:9000/C:/Users/slm/Desktop/tuijian.txt is not a valid DFS filename.
at org.apache.hadoop.hdfs.DistributedFileSystem.getPathName(DistributedFileSystem.java:196)
at org.apache.hadoop.hdfs.DistributedFileSystem.access$000(DistributedFileSystem.java:105)
at org.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:1118)
at org.apache.hadoop.hdfs.DistributedFileSystem$18.doCall(DistributedFileSystem.java:1114)
at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)
at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1114)
at org.apache.hadoop.fs.Globber.getFileStatus(Globber.java:57)
at org.apache.hadoop.fs.Globber.glob(Globber.java:252)
at org.apache.hadoop.fs.FileSystem.globStatus(FileSystem.java:1644)
at org.apache.hadoop.mapred.FileInputFormat.singleThreadedListStatus(FileInputFormat.java:257)
at org.apache.hadoop.mapred.FileInputFormat.listStatus(FileInputFormat.java:228)
at org.apache.hadoop.mapred.FileInputFormat.getSplits(FileInputFormat.java:313)
at org.apache.spark.rdd.HadoopRDD.getPartitions(HadoopRDD.scala:202)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:239)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:237)
可以肯定那个文件件在本地是存在的,但是读取不到;
解决方法
1、若是指定文件路径为 “file://…”,则读取的是本地目录;
2、未指定默认为HDFS文件系统
如果程序中读取的是本地文件,那么,要在所有的节点都有这个数据文件,只在master中有这个数据文件时执行程序时一直报找不到文件
解决方式1:让每个Worker节点的相应位置都有要读取的数据文件。
解决方式2:直接将数据文件上传到hdfs,达到数据共享。