赞
踩
start-dfs.sh
回车
hadoop fs -mkdir /usr
hadoop fs -mkdir /usr/output
touch hello.txt
vim hello.txt
按 fn + delete 进入
输入文字
HDFS的块比磁盘的块大,其目的是为了最小化寻址开销。
在英文键盘下
按esc
shift + :
wq
退出
hadoop fs -put hello.txt /usr/output
为了保险我们查看一下是否上传成功
hadoop fs -cat /usr/output/hello.txt
这里就是上传成功了
hadoop fs -rm -r /user/hadoop
这样就删除成功了
hadoop fs -copyToLocal /usr/output/hello.txt /usr/local
点击命令行进入
touch task.txt
vim task.txt
按 fn + delete 进入
输入
怕什么真理无穷,进一寸有一寸的欢喜。
在英文键盘下
按esc
shift + :
wq
退出
hadoop fs -put task.txt /user/hadoop
hadoop fs -cat /user/hadoop/
结果如下
插入代码
URI uri = URI.create("hdfs://localhost:9000/user/hadoop/task.txt");
Configuration config = new Configuration();
FileSystem fs = FileSystem.get(uri, config);
InputStream in = null;
try {
in = fs.open(new Path(uri));
IOUtils.copyBytes(in, System.out, 2048, false);
} catch (Exception e) {
IOUtils.closeStream(in);
}
mkdir /develop
mkdir /develop/input
cd /develop/input
touch hello.txt
vim hello.txt
按 fn + delete 插入
迢迢牵牛星,皎皎河汉女。
纤纤擢素手,札札弄机杼。
终日不成章,泣涕零如雨。
河汉清且浅,相去复几许?
盈盈一水间,脉脉不得语。
《迢迢牵牛星》
在英文键盘下
按esc
shift + :
wq
退出
File localPath = new File("/develop/input/hello.txt"); String hdfsPath = "hdfs://localhost:9000/user/tmp/hello.txt"; InputStream in = new BufferedInputStream(new FileInputStream(localPath)); Configuration config = new Configuration(); FileSystem fs = FileSystem.get(URI.create(hdfsPath), config); long fileSize = localPath.length() > 65536 ? localPath.length() / 65536 : 1; FSDataOutputStream out = fs.create(new Path(hdfsPath), new Progressable() { long fileCount = 0; public void progress() { System.out.println("总进度" + (fileCount / fileSize) * 100 + "%"); fileCount++; } }); IOUtils.copyBytes(in, out, 2048, true);
结果
String hadoop = "hdfs://localhost:9000/user/hadoop"; String test = "hdfs://localhost:9000/tmp/test"; String root = "hdfs://localhost:9000/"; String tmp = "hdfs://localhost:9000/tmp"; Configuration config = new Configuration(); FileSystem fs = FileSystem.get(URI.create(root), config); fs.delete(new Path(hadoop), true); fs.delete(new Path(test), true); Path[] paths = {new Path(root), new Path(tmp)}; FileStatus[] status = fs.listStatus(paths); Path[] listPaths = FileUtil.stat2Paths(status); for (Path path: listPaths) { System.out.println(path); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。