hdfs 如何进行文件夹和文件的复制

hanger_liu 2016-09-01 05:04:45
我想讲hdfs 里面的文件或者文件夹复制到hdfs上的另一个目录里面,怎么实现呢 ?

求大神帮我!!
...全文
2894 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu492040132 2017-12-01
  • 打赏
  • 举报
回复
hdfs dfs -cp /源目录 /目标目录
y592113978 2017-03-17
  • 打赏
  • 举报
回复
楼主找到解决办法了没,要自己读输入输出流吗?
轩辕兰依 2016-11-09
  • 打赏
  • 举报
回复
hadoop fs -cp /user/hadoop/file1 /user/hadoop/file2
静默QL 2016-09-02
  • 打赏
  • 举报
回复
import java.io.*;
public class Test{
	static String start = "C:\\Users\\Administrator\\Desktop\\网址"; //文件的初始目录
	static String end = "C:\\Users\\Administrator\\Desktop\\网址一"; //文件的结束目录
	public static void main(String[] args) throws Exception{

		File start1 = new File(start);
		find(start1,end);
	}

	public static void find(File start,String end) throws Exception{
		File[] fs = start.listFiles();

		if(fs == null) return;  //不能访问直接返回
		//判断目标文件夹是否存在
		File tmp = new File(end);
		if(!tmp.exists()){
			tmp.mkdirs();//目录
		}
		for(File f:fs){
			if(f.isFile()){
				copy(f,end+"\\"+f.getName());
			}
			if(f.isDirectory()){
				find(f,end+"\\"+f.getName());
			}
		}
	}
	//传输文件
	public static void copy(File f,String endStr) throws Exception{
		System.out.println(endStr);
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(endStr));
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f),1<<10);
		int data;
		while((data = bis.read())!=-1){
			bos.write(data);
		}
		bos.flush();
		bis.close();
		bos.close();

	}

}
hanger_liu 2016-09-02
  • 打赏
  • 举报
回复
有没有大神啊!!
hanger_liu 2016-09-02
  • 打赏
  • 举报
回复
我要的是HDFS的复制,不是本地文件的复制啊

50,532

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧