HDFS上传文件-流方式

import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.ws.rs.core.NewCookie;

import org.apache.commons.compress.utils.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class Test03 {
	static Configuration conf =  new Configuration();
	static FileSystem fs =null;
	public static void main(String[] args) throws IllegalArgumentException, IOException, InterruptedException, URISyntaxException {
		upload();
		
	}
		


	public static void upload() throws IllegalArgumentException, IOException, InterruptedException, URISyntaxException{
		fs = FileSystem.get(new URI("hdfs://hadoop1:9000"),conf,"root");
		FSDataOutputStream out = fs.create(new Path("/input/新建3.txt"));
		FileInputStream in = new FileInputStream("H:/新建.txt");
		IOUtils.copy(in, out); 
		fs.close();
		
	}
}

 

你可能感兴趣的:(hadoop)