从hdfs读取文件引用风暴

nhjlsmyf  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(368)

嗨,我想问个问题。我开始了解Apache风暴。有没有可能在hdfs中读取数据文件。??
示例:我在目录中有一个数据txt文件 /user/hadoop 在hdfs上。有可能突然读到那个文件吗。??thx之前
因为当我尝试运行storm时,如果文件不存在,我会收到一条错误消息。当我尝试从本地存储中读取文件来运行它时,它成功了

>>> Starting to create Topology ...
---> Read Class: FileReaderSpout , 1387957892009
---> Read Class: Split , 1387958291266
---> Read Class: Identity , 247_Identity_1387957902310_1
---> Read Class: SubString , 1387964607853
---> Read Class: Trim , 1387962789262
---> Read Class: SwitchCase , 1387962333010
---> Read Class: Reference , 1387969791518
File /reff/test.txt .. not exists ..
vybvopom

vybvopom1#

当然!下面是如何从hdfs读取文件的示例:

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

// ...stuff...

FileSystem fs = FileSystem.get(URI.create("hdfs://prodserver"), new Configuration());
String hdfspath = "/apps/storm/conf/config.json";
Path path = new Path();
if (fs.exists(path)) {
   InputStreamReader reader = new InputStreamReader(fs.open(path));
   // do stuff with the reader
} else {
   LOG.info("Does not exist {}", hdfspath);
}

这不使用任何特定于storm的东西,只使用HadoopAPI(hadoopcommon.jar)。
你得到的错误看起来像是因为你的文件路径不正确。

相关问题