使用Java API在Hadoop中移动文件? [英] Moving files in Hadoop using the Java API?

查看:1074
本文介绍了使用Java API在Hadoop中移动文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Java API在HDFS中移动文件。我无法想出办法做到这一点。 FileSystem类似乎只想允许移入和移出本地文件系统......但我想将它们保存在HDFS中并将它们移动到那里。



我错过了一些基本的东西吗?我能想到的唯一方法就是从输入流中读取它并将其写回...然后删除旧副本(yuck)。

谢谢

解决方案

使用 FileSystem.rename()


  public abstract boolean rename(Path src,Path dst)throws IOException 
code>

将Path src 重命名为Path dst 。可以在本地fs或远程DFS上进行。

参数
src code> - 要重命名的路径

dst - 重命名后的新路径

返回: strong>

true 如果重命名成功

抛出:
IOException - 失败时



I want to move files around in HDFS using the Java APIs. I cannot figure out a way to do this. The FileSystem class only seems to want to allow moving to and from the local file system.. but I want to keep them in HDFS and move them there.

Am I missing something basic? The only way I can figure to do it is to read it from the input stream and write it back out... and then delete the old copy (yuck).

thanks

解决方案

Use FileSystem.rename():

public abstract boolean rename(Path src, Path dst) throws IOException

Renames Path src to Path dst. Can take place on local fs or remote DFS.

Parameters:
src - path to be renamed
dst - new path after rename
Returns:
true if rename is successful
Throws:
IOException - on failure

这篇关于使用Java API在Hadoop中移动文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆