Hadoop 获取Input File的文件名

 

写Hadoop程序的时候在Mapper里遇到这个需求,上网查了下,做个记录:

public static class MapClass extends MapReduceBase implements
            Mapper<Object, Text, IntWritable, Text> {

        @Override
        public void map(Object k, Text value,
                OutputCollector<IntWritable, Text> output, Reporter reporter)
                throws IOException {
            // TODO Auto-generated method stub

            FileSplit fileSplit = (FileSplit) reporter.getInputSplit();
            String fileName = fileSplit.getPath().getName();
           
        }
    }

 

posted @ 2015-04-01 10:28  tinylcy  阅读(520)  评论(0编辑  收藏  举报