赞
踩
目录
1.创建配置参数对象---Configuration类(org.apache.hadoop.conf.Configuration)
3.创建HDFS文件系统的对象---带配置项---FileSystem类
(2)下载文件:/data/input/word.txt下载到D:/hadoop/hdfs
(3)上传文件:D:/hadoop/hdfs/word.txt上传到/wordcount
(5)上传文件:D:\hadoop\hdfs\word.txt上传到/wordcount/aaa
Configuration x = new Configuration();
x.set("fs.defaultFS","hdfs://master:8020");
FileSystem i = FileSystem.get(x);
操作完成后如图所示
- Path path = new Path("/wordcount");
- fs.mkdirs(path);
- System.out.println("创建成功");
运行成功后可到master:9870上进行查看
- Path src = new Path("/data/input/word.txt");
- Path dst = new Path("D:/HADOOP/hdfs");
- Path src = new Path("D:\\HADOOP\\hdfs\\word.txt");
- Path dst = new Path("/wordcount");
- fs.copyFromLocalFile(src,dst);
- Path path = new Path("/wordcount/aaa");
- fs.mkdirs(path);
- System.out.println("创建成功");
- Path src = new Path("D:\\hadoop\\hdfs\\word.txt");
- Path dst = new Path("/wordcount/aaa");
- fs.copyFromLocalFile(src,dst);
- Path f = new Path("/wordcount/aaa");
- fs.delete(f,true);
- Path src = new Path("/a/hdfs/2.txt");
- Path dst = new Path("/a/hdfs/666.txt");
- fs.rename(src,dst);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。