通过调用Java API实现对HDFS的文件系统的操作-文件拷贝
1. package hdfsapi; 2. 3. import java.io.IOException; 4. import java.net.URI; 5. 6. import org.apache.hadoop.conf.Configuration; 7. import org.apache.hadoop.fs.FileSystem; 8. import org.apache.hadoop.fs.Path; 9. 10. public class E3_CopyFromLocalAPI { 11. 12. public static void main(String[] args) throws IOException, InterruptedException { 13. //获取配置 14. Configuration conf =new Configuration(); 15. //用root用户去获取文件系统对象 16. FileSystem fs = FileSystem.get(URI.create("hdfs://master:8020"), conf, "root"); 17. 18. Path localsrc = new Path("E:\\tmp\\workspace\\word.txt"); 19. fs.copyFromLocalFile(localsrc, new Path("/user/root/")); 20. System.out.println("done!"); 21. } 22. }
理解HDFS Java API编程原理;
掌握HDFS的命令;
掌握Elipse远程调试Hadoop程序的方法;
掌握HDFS基本的API调用方法