2016-12-16 130 views
1

我的机器是windows机器。我正在eclipse IDE中测试我的spark代码。在Spark中读取windows网络文件

我有我的文件sample.txt存储在网络文件夹。

文件的位置属性是\\\aloha\logfolder

我想在sparkcontext中读取它。以下是我的代码片段。

val conf = new SparkConf().setAppName("WordCount").setMaster("local") 
val sc = new SparkContext(conf) 
val inp = sc.textFile("\\\\aloha\\logfolder\\sample.txt") 

但我得到了以下错误:

Exception in thread "main" org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: file://aloha/logfolder/sample.txt 

我曾尝试以下选项,以及。

val inp = sc.textFile("file:\\\\aloha\\logfolder\\sample.txt") 
val inp = sc.textFile('file:\\\\aloha\\logfolder\\sample.txt') 

但似乎没有工作。

当我将同一个文件复制到我的C盘,它的工作。

val inp = sc.textFile("C:\\Desktop\\logfolder\\sample.txt') 

有什么想法我错过了什么?

回答

2

据我所知SparkContext.textfile()无法在Windows上使用UNC路径加载文件。 see similar issue

/** 
    * Read a text file from HDFS, a local file system (available on all nodes), or any 
    * Hadoop-supported file system URI, and return it as an RDD of Strings. 
    */ 
    def textFile(
     path: String, 
     minPartitions: Int = defaultMinPartitions): RDD[String] = withScope { 
    assertNotStopped() 
    hadoopFile(path, classOf[TextInputFormat], classOf[LongWritable], classOf[Text], 
     minPartitions).map(pair => pair._2.toString).setName(path) 
    } 
+0

谢谢拉姆。你知道任何其他解决方法来读取火花中的这些文件吗? – user7264473

+0

使用'robocopy'手动或本地复制它们到hdfs,这是我所知道的唯一的东西。 –