Hadoop MapReduce。无法打开文件以传递参数
Hadoop MapReduce. Trouble opening file to pass parameters
我试图打开一个文件以将文件中读取的一些参数传递给作业 MapReduce。此代码在本地模式下工作,但当我尝试攻击 HDFS 时它不起作用。
这是我的代码:
Path tmpPath = new Path(tmpFile);
try {
InputStream ips = new FileInputStream(tmpFile);
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br = new BufferedReader(ipsr);
String[] minMax = br.readLine().split("-");
min = minMax[0];
max = minMax[1];
br.close();
} catch (Exception e) {
System.out.println(e.toString());
System.exit(-1);
}
这是出现的代码错误:
"java.io.FileNotFoundException: hdfs:/quickstart.cloudera:8020/user/cloudera/dataOut/tmp/part-r-00000 (No such file or directory)"
这是我之前写文件的地方:
Path tmp = new Path("dataOut/tmp");
FileOutputFormat.setOutputPath(job, tmp);
作为 MapReduce 作业,这将写入文件 part-r-00000。
可能大家都会说,"Try with Distributed cache"。
我已经尝试过了,但我是 Java、Hadoop 和 MapReduce 的新手。我无法让它工作...
谢谢
查看您的错误代码
"java.io.FileNotFoundException: hdfs:/quickstart.cloudera:8020/user/cloudera/dataOut/tmp/part-r-00000 (No such file or directory)"
您的输出路径似乎不在给定目录中。
尝试运行下面的命令来检查你是否能够超出路径。
hadoop fs -text hdfs:/quickstart.cloudera:8020/user/cloudera/dataOut/tmp/part-r-00000
我终于明白了。我使用了这段代码:
Configuration conf = new Configuration();
Path file = new Path(DEFAULT_FS + "/user/cloudera/dataOut/tmp/part-r-00000");
FileSystem hdfs = FileSystem.get(file.toUri(), conf);
FSDataInputStream in = hdfs.open(file);
byte[] content = new byte[(int) hdfs.getFileStatus(file).getLen()];
in.readFully(content);
String maxMin = new String(content);
我试图打开一个文件以将文件中读取的一些参数传递给作业 MapReduce。此代码在本地模式下工作,但当我尝试攻击 HDFS 时它不起作用。
这是我的代码:
Path tmpPath = new Path(tmpFile);
try {
InputStream ips = new FileInputStream(tmpFile);
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br = new BufferedReader(ipsr);
String[] minMax = br.readLine().split("-");
min = minMax[0];
max = minMax[1];
br.close();
} catch (Exception e) {
System.out.println(e.toString());
System.exit(-1);
}
这是出现的代码错误:
"java.io.FileNotFoundException: hdfs:/quickstart.cloudera:8020/user/cloudera/dataOut/tmp/part-r-00000 (No such file or directory)"
这是我之前写文件的地方:
Path tmp = new Path("dataOut/tmp");
FileOutputFormat.setOutputPath(job, tmp);
作为 MapReduce 作业,这将写入文件 part-r-00000。
可能大家都会说,"Try with Distributed cache"。 我已经尝试过了,但我是 Java、Hadoop 和 MapReduce 的新手。我无法让它工作...
谢谢
查看您的错误代码 "java.io.FileNotFoundException: hdfs:/quickstart.cloudera:8020/user/cloudera/dataOut/tmp/part-r-00000 (No such file or directory)"
您的输出路径似乎不在给定目录中。 尝试运行下面的命令来检查你是否能够超出路径。
hadoop fs -text hdfs:/quickstart.cloudera:8020/user/cloudera/dataOut/tmp/part-r-00000
我终于明白了。我使用了这段代码:
Configuration conf = new Configuration();
Path file = new Path(DEFAULT_FS + "/user/cloudera/dataOut/tmp/part-r-00000");
FileSystem hdfs = FileSystem.get(file.toUri(), conf);
FSDataInputStream in = hdfs.open(file);
byte[] content = new byte[(int) hdfs.getFileStatus(file).getLen()];
in.readFully(content);
String maxMin = new String(content);