尝试从 hdfs 输出中读取 hadoop
try to hadoop read from hdfs output
这是我的程序,我想从我的 hdfs 中读取它是我使用 map reduce 程序创建的,但它不显示任何输出。没有任何编译时间和 运行 时间错误。
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Cat{
public static void main (String [] args) throws Exception{
try{
Path pt=new Path("hdfs:/path/to/file");
FileSystem fs = FileSystem.get(new Configuration());
BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt)));
String line;
line=br.readLine();
while (line != null){
System.out.println(line);
line=br.readLine();
}
}catch(Exception e){
}
}
}
我不能发表评论,所以我会post回答。
处理该异常可能会有所帮助。你到底抓到了什么?
注意事项:
1) 您使用的 hdfs 路径是否正确?
如果您在本地机器上使用 cloudera,路径应该如下所示。
Path pt=new Path("hdfs://localhost.localdomain:8020/user/cloudera/myfile.txt");
检查 core-site.xml 中的 "fs.defaultFS" 属性 以获取文件系统路径(即 hdfs://something.something:port/)
2) 你是如何执行代码的?
尝试使用以下命令
从 CLI 创建一个 jar 和 运行
$ hadoop jar /home/cloudera/your/path/to/jar/myjar.jar com.test.Myjar
试试上面的方法,如果有效请告诉我们。
HTH
这是我的程序,我想从我的 hdfs 中读取它是我使用 map reduce 程序创建的,但它不显示任何输出。没有任何编译时间和 运行 时间错误。
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Cat{
public static void main (String [] args) throws Exception{
try{
Path pt=new Path("hdfs:/path/to/file");
FileSystem fs = FileSystem.get(new Configuration());
BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt)));
String line;
line=br.readLine();
while (line != null){
System.out.println(line);
line=br.readLine();
}
}catch(Exception e){
}
}
}
我不能发表评论,所以我会post回答。
处理该异常可能会有所帮助。你到底抓到了什么?
注意事项:
1) 您使用的 hdfs 路径是否正确?
如果您在本地机器上使用 cloudera,路径应该如下所示。
Path pt=new Path("hdfs://localhost.localdomain:8020/user/cloudera/myfile.txt");
检查 core-site.xml 中的 "fs.defaultFS" 属性 以获取文件系统路径(即 hdfs://something.something:port/)
2) 你是如何执行代码的? 尝试使用以下命令
从 CLI 创建一个 jar 和 运行$ hadoop jar /home/cloudera/your/path/to/jar/myjar.jar com.test.Myjar
试试上面的方法,如果有效请告诉我们。
HTH