会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
韩佳龙
博客园
首页
新随笔
联系
订阅
管理
11.12
hdfs基本操作1
1
|1
创建目录
//创建目录 public static void mkdir(String filePath) throws URISyntaxException, IOException, InterruptedException{ FileSystem fs = FileSystem.get(new URI("hdfs://hadoop101:8020"), new Configuration(), "root"); Path path= new Path(filePath); fs.mkdirs(path); System.out.println("目录创建成功:"+filePath); fs.close(); }
1
|
2
创建文件
//创建文件 public static void createFile(String remoteFilePath)throws URISyntaxException, IOException, InterruptedException { FileSystem fs = FileSystem.get(new URI("hdfs://hadoop101:8020"), new Configuration(), "root"); Path remotePath = new Path(remoteFilePath); FSDataOutputStream outputStream = fs.create(remotePath); outputStream.close(); System.out.println("文件创建成功!!"+remoteFilePath); }
1
|
3
删除文件
//删除文件 public static void deleteFile(String filePath) throws URISyntaxException, IOException, InterruptedException{ FileSystem fs = FileSystem.get(new URI("hdfs://hadoop101:8020"), new Configuration(), "root"); Path path= new Path(filePath); if(fs.deleteOnExit(path)) { System.out.println("文件删除成功:"+filePath); } else { System.out.println("文件删除失败:"+filePath); } fs.close(); }
1
|
4
移动文件到本地
// 移动文件到本地 public static void moveToLocalFile(String remoteFilePath, String localFilePath) throws IOException, InterruptedException, URISyntaxException { FileSystem fs = FileSystem.get(new URI("hdfs://hadoop101:8020"), new Configuration(), "root"); Path remotePath = new Path(remoteFilePath); Path localPath = new Path(localFilePath); fs.moveToLocalFile(remotePath, localPath); }
posted @
2021-11-12 13:58
韩佳龙
阅读(
74
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告