FileSystem fs = FileSystem.get(new Configuration());
FSDataInputStream fis = fs.open(new Path("****"));
BufferedReader reader = new BufferedReader(new InputStreamReader(
fis));
StringBuilder sb = new StringBuilder();
while (true) {
String line = reader.readLine();
// empty string, email headers and body are separated by an
if (line == null || line.length() == 0)
break;
sb.append(line);
sb.append('/n');
}
Fis.close();
Sb.toString()就是读取到的hdfs的内容了。
写HDFS
FSDataOutputStream fos = fs.create(new Path(""));
fos.write(new byte[1024]);
fos.close();
以后会把HDFS读、写的原理发出来。