Socialabel

Saturday, August 24, 2013

Java Code Hadoop Copy File dari HDFS ke Local Hardisk

Lanjutan dari HDFS yang berhubungan dengan sistem berkas, coding dibawah ini merupakan listen java yang berfungsi untuk mengkopi file dari HDFS ke lokal hardisk

 package hery.its.tesis.bigdata.copytolokal;  
   
 import org.apache.hadoop.fs.*;  
 import org.apache.hadoop.conf.*;  
   
 public class CopyHadoop2{  
     public static void main (String [] args) throws Exception  
     {      
            //Membuat Koneksi ke HDFS  
            Configuration konfigurasi = new Configuration();  
            konfigurasi.set("fs.default.name","hdfs://master:54310/");  
            FileSystem dfs = FileSystem.get(konfigurasi);  
              
            //Salin file dari HDFS ke Local Hardisk
            Path src = new Path(dfs.getWorkingDirectory()+"/a");
            Path dst = new Path("/tmp/tmp/a.lokal");
            dfs.copyToLocalFile(src, dst);
            System.out.println("Mengkopi file HDFS "+src+" Ke "+dst);
     }  
 }  

yang terpenting adalah remote HDFS sesuaikann dengan port pada node master masing-masing

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete