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

读取hdfs文件系统中的资料

2013-03-12 
读取hdfs文件系统中的文件从hdfs中下载文件,下载的文件默认存储在E:盘下,如需修改下载路径,只需修改downlo

读取hdfs文件系统中的文件

从hdfs中下载文件,下载的文件默认存储在E:盘下,如需修改下载路径,只需修改downloadPath,具体代码:

public static void readFromHdfs(String filename,String downloadPath) throws FileNotFoundException,IOException {  String dst = "hdfs://192.168.248.129:9000/"+filename;  Configuration conf = new Configuration();  FileSystem fs = FileSystem.get(URI.create(dst), conf);  FSDataInputStream hdfsInStream = fs.open(new Path(dst));  OutputStream out = new FileOutputStream(downloadPath);  byte[] ioBuffer = new byte[1024];  int readLen = hdfsInStream.read(ioBuffer);  while(-1 != readLen){  out.write(ioBuffer, 0, readLen);  readLen = hdfsInStream.read(ioBuffer);  }  out.close();  hdfsInStream.close();  fs.close(); }

?

热点排行