Naveen
Naveen

Reputation: 455

Copy hdfs file to another hdfs location using java

I need to copy hdfs file to another location in hdfs using Java. The source should not be deleted, just want to copy the source file with new filename in target hdfs location.

I could see only copyFromLocal, copyToLocal or rename in FileSystem.java class.

Can anyone tell if there is any method just to copy hdfs file with new name into source directory?

Upvotes: 1

Views: 5078

Answers (2)

Evgeny Benediktov
Evgeny Benediktov

Reputation: 1399

Use copy function of class FileUtil:

From the javadoc (http://hadoop.apache.org/docs/stable/api/org/apache/hadoop/fs/FileUtil.html):

public static boolean copy(FileSystem srcFS,
                       Path src,
                       FileSystem dstFS,
                       Path dst,
                       boolean deleteSource,
                       boolean overwrite,
                       Configuration conf)
                throws IOException

Upvotes: 1

ctutte
ctutte

Reputation: 131

You can always read input and save it as a new file at desired destination

Upvotes: 0

Related Questions