赞
踩
操作系统:Ubuntu 16.04
Hadoop 版本:3.1.3
JDK 版本:1.8
Java IDE:IDEA2020
开启hadoop服务:
创建两个文档用于实验
出现"hadoop:未找到命令"错误,解决方案有以下两种
1.在执行hadoop命令前加上“./sbin”,例如上图可以改为”./sbin/hadoop fs -cat local.txt“
2.shell命令修改环境变量 : export PATH=$PATH:/usr/local/hadoop/bin ,路径为hadoop安装路径。
上传cloud.txt文档
将local.txt内容追加到cloud.txt末尾
将local.txt内容覆盖到cloud.txt
hadoop fs -copyFromLocal local.txt cloud.txt
if $(hadoop fs -test -e /usr/local/hadoop/cloud/txt);
then $(hadoop fs -copyToLocal cloud.txt ./cloud.txt);
else $(hadoop fs -copyToLocal cloud.txt ./cloud2.txt);
fi
hadoop fs -cat cloud.txt
hadoop fs -ls -h cloud.txt
hadoop fs -lsr -h /
hadoop fs -touch /test/test.txt //所在目录不存在时,创建新的空白文件
hadoop fs -rm -R /test/test.txt //删除文件
hadoop fs -mkdir -p file1/file2
hadoop fs -touchz file1/file2/test.txt
hadoop fs -rm -r file1/file2
hadoop fs -appendTofile local.txt cloud.txt //将本地local.txt的内容添加到cloud.txt的末尾
hadoop fs -rm ./cloud.txt //注意是删除HDFS中文件,本地的local.txt文件无法删除,会出现如图找不到此文件错误
hadoop fs -rmr file1/file2
hadoop fs -mv /usr/local/hadoop/from.txt /usr/local/hadoop/to.txt
public class read {
public void read() throws Exception{
FSDataInputStream f = fileSystem.open(new path("/usr/local/hadoop/test.txt"));
BufferedReader re = new BufferedReader(new InputStreamReader(f,"UTF-8"));
System.out.println(re.readLine());
re.close();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。