[英]Copy Json Flat file from local to HDFS
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 getting following error message " Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at com.Main.Main.main(Main.java:22) " AM收到以下错误消息“ 线程“ main ”中的异常java.lang.ArrayIndexOutOfBoundsException:com.Main.Main.main(Main.java:22)为0 ”
I have Json file in my local , have to move that in HDFS Ex: {"Del":"Ef77xvP","time":1509073785106}, {"Del":"2YXsF7r","time":1509073795109} 我本地有Json文件,必须在HDFS Ex中移动它: {“ Del”:“ Ef77xvP”,“ time”:1509073785106},{“ Del”:“ 2YXsF7r”,“ time”:1509073795109}
Specify command line arguments to your program. 指定程序的命令行参数。 You code snippet expects first argument to be source and next arguments to be destination.
您的代码片段期望第一个参数为源,而下一个参数为目标。 For more details refer to What is "String args[]"?
有关更多详细信息,请参阅什么是“ String args []”? parameter in main method Java
主方法Java中的参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.