我想读一小txt文件,该文件是加入作为表的默认数据库上Databricks. 在试图读取文件的通过地方文件API,我得到一个 FileNotFoundError
但我能读相同的文件作为 火花RDD 使用 SparkContext.
请找到代码如下:
with open("/FileStore/tables/boringwords.txt", "r") as f_read:
for line in f_read:
print(line)
这给了我错误:
FileNotFoundError Traceback (most recent call last)
<command-2618449717515592> in <module>
----> 1 with open("dbfs:/FileStore/tables/boringwords.txt", "r") as f_read:
2 for line in f_read:
3 print(line)
FileNotFoundError: [Errno 2] No such file or directory: 'dbfs:/FileStore/tables/boringwords.txt'
在那里,我有没有问题,阅读该文件,使用 SparkContext:
boring_words = sc.textFile("/FileStore/tables/boringwords.txt")
set(i.strip() for i in boring_words.collect())
并且正如预期的,我得到的结果对于上述块代码:
Out[4]: {'mad',
'mobile',
'filename',
'circle',
'cookies',
'immigration',
'anticipated',
'editorials',
'review'}
我还指 出文件 来了解当地的文件API的限制,但没有导致对这个问题。 任何帮助,将不胜感激。 谢谢!