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");
}
}
我收到以下错误消息“exception in thread”main“java.lang.arrayindexoutofboundsexception:0 at com.main.main.main(main。java:22)"
我的本地有json文件,必须在hdfs中移动它,例如:{“del”:“ef77xvp”,“time”:1509073785106},{“del”:“2yxsf7r”,“time”:1509073795109}
1条答案
按热度按时间gkl3eglg1#
为程序指定命令行参数。您的代码段期望第一个参数是源,下一个参数是目标。有关更多详细信息,请参阅什么是“字符串参数[]”?主方法java中的参数