1.工程中引入的依赖
<dependency>
<groupId> org.apache.hadoop</groupId>
<artifactId>hadoop-client </artifactId>
<version>2.6.0</version>
</dependency>
2.两种实现机制
实现1:
static{
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
}
public static void main(String[] args) throws Exception
{
String hdfsAddress="hdfs://localhost";
InputStream in = new URL(hdfsAddress+"/henry/log/access.log-2015-01-19").openStream();
//System.out.println(in);
IOUtils.copyBytes(in, System.out, 4096, false);
IOUtils.closeStream(in);
}
public static void main(String[] args) throws Exception
{
String hdfsAddress="hdfs://localhost";
String uri = hdfsAddress+"/henry/log/access.log-2015-01-19";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
InputStream in = fs.open(new Path(uri));
IOUtils.copyBytes(in, System.out, 4096, false);
IOUtils.closeStream(in);
}