How to Copy a File from Local System to HDFS

  • //To create a new directory
    Sample Code Segment

    Path sourcepath = new Path("user/D/filelLocation");
    Path despath = new Path("hdfs://slogix.in:54310/home/hduser/hadoopfile”);
    FileSystem fs = FileSystem.get(conf);
    fs.copyFromLocalFile(sourcepath, despath);

    Command

    hadoop fs -copyFromLocal <sourcepath> <despath>