首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

HDFS 中写下数据

2012-06-27 
HDFS 中写入数据?import java.io.BufferedInputStreamimport java.io.FileInputStreamimport java.io.IO

HDFS 中写入数据

?

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;

import org.apache.hadoop.util.Progressable;

public class FileCopyWithProgress {

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

String localSrc = "e://45025778_18.txt";

String hdfsDest = "hdfs://192.168.1.150:9000/tmp/a.txt"; // HDFS中存储的文件名

InputStream in = new BufferedInputStream(new FileInputStream(localSrc));

Configuration conf = new Configuration();

FileSystem fs = ?FileSystem.get(URI.create(hdfsDest), conf);

OutputStream out = fs.create(new Path(hdfsDest),new Progressable(){

public void progress(){

System.out.println(".");

}

});

IOUtils.copyBytes(in, out, 4096,true);

}

}


热点排行