不单独说明了,代码中的注释很详细了
-
-
-
-
-
-
-
-
- public class FileSystemCatSeekable {
-
- public static void main(String [] args) throws Exception{
-
-
- String uri = args[0];
-
- Configuration conf = new Configuration();
- conf.set("hadoop.job.ugi", "root,root123");
-
-
-
- FileSystem fs = FileSystem.get(URI.create(uri) ,conf);
-
-
- FSDataInputStream in = null;
-
- try{
-
-
- in =fs.open(new Path (uri));
-
-
- IOUtils.copyBytes(in, System.out, 20, false);
-
-
- in.seek(0);
-
-
- IOUtils.copyBytes(in, System.out, 20, false);
-
- }catch (Exception ex){
- ex.printStackTrace();
- }finally{
- in.close();
- }
- }
- }
本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/840725,如需转载请自行联系原作者