创建目录 -mkdir
hadoop fs -mkdir -p /aaa/bbb
从本地剪切文件到hdfs -moveFromLocal
hadoop fs -moveFromLocal ./file.txt /aaa/
从本地复制文件到hdfs -copyFromLocal
hadoop fs -copyFromLocal ./file.txt /aaa/
从hdfs剪切文件到本地 -moveToLocal
hadoop fs -moveToLocal /aaa/file.txt /folder/
从hdfs复制文件到本地 -copyToLocal
hadoop fs -copyToLocal /aaa/file.txt /folder/
删除文件或文件夹 -rm
hadoop fs -rm -r /aaa/bbb/
HDFS读取文件代码
public class HDFSFileReader {
public static void main(String[] args) {
try {
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path filename = new Path("hdfs://localhost:9000/user/hadoop/test.txt");
FSDataInputStream is = fs.open(filename);
BufferedReader d = new BufferedReader(new InputStreamReader(is));
String content = d.readLine();
System.out.println(content);
d.close();
fs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
网友评论