大型数据库技术(一)

package hjy.hadoop;

 

import java.io.FileOutputStream;

import java.io.IOException;

import java.net.URI;

import java.net.URISyntaxException;

 

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.FSDataInputStream;

import org.apache.hadoop.fs.FileSystem;

import org.apache.hadoop.fs.Path;

 

public class MyFSDataInputStream {

 

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

FileSystem fs = null;

FSDataInputStream fsdInputStream = null;

FileOutputStream fos = null;

fos = new FileOutputStream("d:/hhd.txt");

Configuration conf = new Configuration();

conf.set("fs.defaultFS", "hdfs://hjy:9000");

fs = FileSystem.get(new URI("hdfs://hjy:9000"),conf,"hadoop");

 

 Path srcPath = new Path("hdfs://hjy:9000/aa/qingshu.txt");

 fsdInputStream = fs.open(srcPath);

 byte[] buff = new byte[1024];

         int readCount = 0;

         readCount = fsdInputStream.read(buff);

         if(readCount==-1) {

          System.out.println("文本为空!");

          System.exit(0);

         }

         while (readCount != -1) {

          fos.write(buff, 0, readCount);

             System.out.println(new String(buff, 0, readCount));   //阅读文本内容

             readCount = fsdInputStream.read(buff); //下载文本内容

         }

         fos.close();

}

 

}

截图:

大型数据库技术(一)_第1张图片

 

 大型数据库技术(一)_第2张图片

 

转载于:https://www.cnblogs.com/goubb/p/11524892.html

你可能感兴趣的:(大型数据库技术(一))