HDFS的API操作-文件的上传和下载
生活随笔
收集整理的這篇文章主要介紹了
HDFS的API操作-文件的上传和下载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
HDFS 文件上傳
@Test public void putData() throws Exception{FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.52.250:8020"), new Configuration());fileSystem.copyFromLocalFile(new Path("file:///c:\\install.log"),new Path("/hello/mydir/test"));fileSystem.close(); }下載文件到本地
@Test public void getFileToLocal()throws Exception{FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.52.250:8020"), new Configuration());FSDataInputStream open = fileSystem.open(new Path("/test/input/install.log"));FileOutputStream fileOutputStream = new FileOutputStream(new File("c:\\install.log"));IOUtils.copy(open,fileOutputStream );IOUtils.closeQuietly(open);IOUtils.closeQuietly(fileOutputStream);fileSystem.close(); }?
總結
以上是生活随笔為你收集整理的HDFS的API操作-文件的上传和下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDFS的API操作-创建文件和文件夹
- 下一篇: HDFS的API操作-访问权限问题