首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >hdfs查看命令_windows命令提示符窗口

hdfs查看命令_windows命令提示符窗口

作者头像
全栈程序员站长
发布2022-11-09 17:18:42
发布2022-11-09 17:18:42
1.5K0
举报
代码语言:javascript
复制
public class HdfsClient1 {
private FileSystem fs;
//初始化一个FileSystem
@Before
public void init() throws URISyntaxException, IOException, InterruptedException {
//1:获取文件系统
URI uri = new URI("hdfs://myhadoop105:9820");
Configuration conf = new Configuration();
conf.set("dfs.replication","6");
String user = "atguigu";
fs = FileSystem.get(uri, conf, user);
}
@After
public void closeResources() throws IOException {
//3:关闭资源
fs.close();
}
@Test
public void testMkdir() throws IOException {
fs.mkdirs(new Path("/hdfs/windowsOperator/operator01"));
}
@Test
public void testPut() throws IOException {
fs.copyFromLocalFile(false , false , new Path("G:/code/test/day08课堂记录.txt") , new Path("/hdfs/windowsOperator/operator01"));
}
@Test
public void testGet() throws IOException {
fs.copyToLocalFile(new Path("/hdfs/windowsOperator/operator01"),new Path("G:\\code\\test\\test"));
}
@Test
public void testMove() throws IOException {
fs.rename(new Path("/hdfs/windowsOperator/day08课堂记录.txt"),new Path("/hdfs/windowsOperator/day08"));
}
@Test
public void testDelete() throws IOException {
fs.delete(new Path("/hdfs/windowsOperator/operator01"),true);
}
@Test
public void testIsFile() throws IOException {
FileStatus[] fileStatuses = fs.listStatus(new Path("/"));
for (FileStatus fileStatus : fileStatuses) {
//判断是否是文件
if (fileStatus.isFile()){
System.out.println("-:"+fileStatus.getPath().getName());
}else {
System.out.println("d:" + fileStatus.getPath().getName());
}
}
}
@Test
public void testListFiles() throws IOException {
// f:要查看的目录路径
// r:是否递归查看
RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);
while (listFiles.hasNext()){
LocatedFileStatus fileStatus = listFiles.next();
System.out.println("-------------------------" + fileStatus.getPath() + "--------------------");
System.out.println(fileStatus.getPermission());
System.out.println(fileStatus.getOwner());
System.out.println(fileStatus.getGroup());
System.out.println(fileStatus.getLen());
System.out.println(fileStatus.getModificationTime());
System.out.println(fileStatus.getReplication());
System.out.println(fileStatus.getBlockLocations());
System.out.println(fileStatus.getPath().getName());
//快信息
BlockLocation[] blockLocations = fileStatus.getBlockLocations();
System.out.println(Arrays.toString(blockLocations));
}
}
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/186043.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年10月4日 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档