Path dst不知道怎么设置呀,和书上设置一样但有不能复制文件过去。
代碼:
package hdfs_api1;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class CopyFile {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
Configuration conf=new Configuration();
FileSystem hdfs=FileSystem.get(conf);
Path src=new Path("/t1.java");
//Path dst=new Path("hdfs://localhost:9000/user/root/in");
Path dst=new Path("/");
hdfs.copyFromLocalFile(src, dst);
System.out.println("Upload to "+conf.get("fs.default.name"));
FileStatus files[]=hdfs.listStatus(dst);
for(FileStatus file:files)
{
System.out.println(file.getPath());
}
}
}
结果如下
代碼:
Upload to file:///
file:/lost+found
file:/etc
file:/media
file:/bin
file:/boot
file:/dev
file:/home
file:/lib
file:/mnt
file:/opt
file:/proc
file:/root
file:/run
file:/sbin
file:/selinux
file:/srv
file:/sys
file:/tmp
file:/usr
file:/var
file:/vmlinuz
file:/initrd.img
file:/cdrom
file:/t1.class
file:/t1.java
file:/user
file:/ss
要是改为Path dst=new Path("hdfs://localhost:9000/user/root/in");又会报错,如下
Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS:
hdfs://localhost:9000/user/root/in, expected: file:///
顺便想知道HDFS中的文件放在哪里了?在根目录中搜索不到呢?