下面是使用java访问hdfs的代码
try {
Configuration config = new Configuration();
config.set("fs.defaultFS","hdfs://192.168.28.153:9000/");
FileSystem dfs = FileSystem.get(config);
Path pt = new Path("hdfs://192.168.28.153:9000/user/hduser/wordcountinput/input.txt");
config.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
BufferedReader br = new BufferedReader(new InputStreamReader(dfs.open(pt)));
String line;
line = br.readLine();
while ((line = br.readLine()) != null) {
System.out.println(line);
line = br.readLine();
}
执行之后,我得到以下异常:
WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the
log4j.properties files. No FileSystem for scheme:
hdfsjava.io.IOException: No FileSystem for scheme: hdfs
at
org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2138)
org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2145)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:80)
有任何连接问题吗?我需要这方面的帮助,这样我才能继续下去。是缺少资源还是其他什么。
1条答案
按热度按时间ki0zmccv1#
只需使用特定的jar。有一堆不合适的jar。