我想我的第一個代碼將文件從HDFS複製到本地文件系統。但是,我無法複製,即使這些文件已預先設置好,但我收到了異常:FileNotFoundExceptoin
。Hadoop文件未找到異常
這裏是我的代碼: -
public class Exercise1 {
public static void main(String[] args) throws IOException ,URISyntaxException {
// TODO Auto-generated method stub
Path glob = new Path("/training/exercises/filesystem/*.txt");
String localRoot = "/home/hadoop/Training/play_area/exercises/filesystem/e1/";
FileSystem hdfs = FileSystem.get(new Configuration());
FileStatus [] files = hdfs.globStatus(glob);
for (FileStatus file : files) {
Path from = file.getPath();
Path to = new Path(localRoot, file.getPath().getName());
System.out.println("Copying hdfs file [" + from + "] to local [" + to + "]");
hdfs.copyToLocalFile(from, to);
}
}
}
我得到的錯誤是: -
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.io.FileNotFoundException: File /training/exercises/filesystem does not exist
at org.apache.hadoop.fs.RawLocalFileSystem.listStatus(RawLocalFileSystem.java:315)
at org.apache.hadoop.fs.FileSystem.listStatus(FileSystem.java:1281)
at org.apache.hadoop.fs.FileSystem.listStatus(FileSystem.java:1321)
at org.apache.hadoop.fs.ChecksumFileSystem.listStatus(ChecksumFileSystem.java:557)
at org.apache.hadoop.fs.FileSystem.listStatus(FileSystem.java:1281)
at org.apache.hadoop.fs.FileSystem.listStatus(FileSystem.java:1358)
at org.apache.hadoop.fs.FileSystem.globStatusInternal(FileSystem.java:1488)
at org.apache.hadoop.fs.FileSystem.globStatus(FileSystem.java:1443)
at org.apache.hadoop.fs.FileSystem.globStatus(FileSystem.java:1421)
at hdfs.javaAPI.Exercise1.main(Exercise1.java:24)
幫我解決這個錯誤。
需要更改的任何文件在什麼??? – daivik
@daivik不需要!也許你的HDFS確實不存在那個文件! – Guo