CopyFromLocal to hdfs using java jar file

CopyFromLocal to hdfs using java jar file
1. Open eclipse and one new class HDFS and write the command as given below:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class HDFS
{
    public static void main(String[] args) throws Exception
    {
        copyFromLocal(args[0],args[1]);
    }
    public static void copyFromLocal(String src, String dest) throws Exception
    {
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        Path srcPath= new Path(src);
        Path destPath = new Path(dest);
        fs.copyFromLocalFile(srcPath, destPath);
        System.out.println("File Copied");
        fs.close();
    }
}

2.After u have completed typing above command go to file and select export
3. Click java and select Runnable JAR file then click next
4. Select HDFS-traininch configuation
5. Export destination just give the path u want to save: /home/cloudera/copyfile.java and then click finish.
6. to copy file from command using our java file syntax.
$ hadoop jar copyfile.java HDFS <input path> <output hdfs path>

No comments:

Post a Comment