public class TestMain {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://xxx.28.xxx.51:9000");
FileSystem dfs = FileSystem.get(conf);
Path filenamePath = new Path("/home/hadoop/data/flume/20130529/12/ch1.1369796403013");
FSDataInputStream fsIn = dfs.open(filenamePath);
// org.apache.commons.io.IOUtils
byte[] fileBytes = IOUtils.toByteArray(fsIn);
fsIn.read(fileBytes);
//create string from byte array
String strFileContent = new String(fileBytes);
System.out.println(strFileContent);
}
}
No comments:
Post a Comment