2017-10-28 7 views
0
package com.Main; 

import java.io.BufferedInputStream; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.net.URI; 

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.FileSystem; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.IOUtils; 



public class Main { 

    public static void main(String[] args) throws IOException { 

     //Source file in the local file system 
     String localSrc = args[0]; 

     //Destination file in HDFS 
     String dst = args[1]; 

     //Input stream for the file in local file system to be written to HDFS 
     InputStream in = new BufferedInputStream(new FileInputStream(localSrc)); 

     //Get configimport org.apache.commons.configuration.Configuration;uration of Hadoop system 
     Configuration conf = new Configuration(); 
     System.out.println("Connecting to -- "+conf.get("fs.defaultFS")); 

     //Destination file in HDFS 
     FileSystem fs = FileSystem.get(URI.create(dst), conf); 
     OutputStream out = fs.create(new Path(dst)); 

     //Copy file from local to HDFS 
     IOUtils.copyBytes(in, out, 4096, true); 

     System.out.println(dst + " copied to HDFS"); 
    } 

} 

AMなって、次のエラーメッセージがメインの "java.lang.ArrayIndexOutOfBoundsException」スレッドで例外":com.Main.Main.mainで0 (Main.java:22) "コピーJSONフラットファイル

私は、私の地元でのJSONファイルを持ってHDFS 例でそれを移動する必要があります。 {" デル ":" Ef77xvP " "時間":1509073785106}、 { "デル":" 2YXsF7r "、"時間 ":1509073795109}

+0

をご覧ください。実行時にJARに引数を提供していますか? – philantrovert

+0

'hdfs dfs -put file.json' ...それほど難しくない –

答えて

0

Speプログラムにコマンドライン引数をcifyします。コードスニペットは、最初の引数がソースであり、次の引数が宛先であると想定しています。 詳細については、What is "String args[]"? parameter in main method Java

+0

プログラムにコマンドライン引数を指定する - >これを取得していない、簡単に説明できますか? – user3214361

+0

eclipse:https://stackoverflow.com/questions/12222153/eclipse-how-we-take-arguments-for-main-when-run intellij:https://stackoverflow.com/questions/32951846/run-programme -from-intellij-with-command-line-file-input –

関連する問題