从本地读取文件,缓存到map集合中
static Map<String, String> question =new HashMap<String, String>();
BufferedReader bf = new BufferedReader(new FileReader("文件名"))
while((line=bf.readLine())!=null) {
if( line.split("\\001").length<3) {return;}
String[] split = line.split("\\001");
question.put(split[0],split[2]+"\\001"+split[3]);
}
缓存hdfs文件
Configuration conf = context.getConfiguration();
FileSystem fs=null;
try {
fs=FileSystem.get(new URI("hdfs://slm001:9000"),conf);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FSDataInputStream in = fs.open(new
Path("hdfs://slm001:9000/user/kk/question/part-m-00000"));
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line = br.readLine())!=null) {
if( line.split("\\001").length<3) {return;}
String[] split = line.split("\\001");
}
in.close();
br.close();