gpt4 book ai didi

java - 将Json Flat文件从本地复制到HDFS

转载 作者:行者123 更新时间:2023-12-02 20:48:21 26 4
gpt4 key购买 nike

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:0
在com.Main.Main.main(Main.java:22)上


我本地有Json文件,必须在HDFS中移动它
例如:
{“Del”:“Ef77xvP”,“时间”:1509073785106},
{“Del”:“2YXsF7r”,“时间”:1509073795109}

最佳答案

指定程序的命令行参数。您的代码段期望第一个参数为源,而下一个参数为目标。
有关更多详细信息,请引用What is "String args[]"? parameter in main method Java

关于java - 将Json Flat文件从本地复制到HDFS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46989931/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com