1、读取mr的结果输出目录
public static List<String> getHdfsFileColumns(Stirng path){
List<String> colimns = new ArrayList<String>();
InputStreamReader isr = null;
BufferedReader br = null;
try{
Configuration conf = new Configuration();
conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributeFileSystem");
FileSystem fs = FileSystem.get(URI.create(path),conf);
FileStatus [] status = fs.listStatus(new Path(path));
for (FileStatus file : status){
if(!file.getPath().getName.startWith("part-r")){
continue;
}
FSDataInputStream fsdata = fs.open(file.getPath());
isr = new InputStreamReader(fsdata);
br = new BufferedReader(isr);
String line = "";
while((line = br.readLine())!=null){
columns.add(line);
}
}
isr.close();
br.close();
}catch (Exception e){
e.printStackTrace();
}
}
2、将数据写到hdfs
public static List<String> getHdfsFileColumns(Stirng path){
List<String> colimns = new ArrayList<String>();
InputStreamReader isr = null;
BufferedReader br = null;
try{
Configuration conf = new Configuration();
conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributeFileSystem");
FileSystem fs = FileSystem.get(URI.create(path),conf,"root");
FSDataOutputStream out= fs.create(new Path(path));
byte [] bb ="abc".getBytes();
out.write(bb);
out.close();
}catch(Exceptionn e){
e.printStackTrace();
}
}
}