一、HDFS读文件过程
1.1 实例代码:
package com.liangjya.hadoop.demo;
import java.io.File;
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;
import org.apache.hadoop.io.IOUtils;
import org.junit.Before;
public class HDFSDemo {
FileSystem fSystem =null;
@Before
public void init() throws IOException, URISyntaxException{
fSystem = FileSystem.get(new URI("hdfs://simulate:9000"), new Configuration());
}
public static void main(String args[]){
try {
FileSystem fSystem = FileSystem.get(new URI("hdfs://simulate:9000"), new Configuration());
FSDataInputStream in=fSystem.open(new Path("/words"));
FileOutputStream out = new FileOutputStream(new File("/usr/cloud/hadoop-words"));
IOUtils.copyBytes(in, out, 2048, true);
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
1.2 读取过程图:
1.初始化FileSystem,