1) Obtain file system
Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf);2) Get list of file by path and read all files line by line:
FileStatus[] fileStatuses = fs.listStatus(new Path(path)); for (FileStatus fileStatus : fileStatuses) { System.out.println("fileStatus: " + fileStatus.getPath().getName()); if (!fileStatus.isFile()) continue; BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new InputStreamReader(fs.open(fileStatuses[0].getPath()))); String line; while ((line = bufferedReader.readLine()) != null) { ... } } finally { IOUtils.closeStream(bufferedReader); } }3) write to file
BufferedWriter out = null; try { out = new BufferedWriter(new OutputStreamWriter(fs.create(new Path(path + "result.txt")))); out.write("text"); } finally { IOUtils.closeStream(out); }