我试图从Map器中的输入文件中读取一条记录,我不想处理那些有空格的记录。不幸的是,即使是有空格的记录也正在被处理。你能告诉我吗?
代码:
@Override
protected void setup(Context context) throws IOException, InterruptedException {
BufferedReader bufferedReader = new BufferedReader(new FileReader("smallData.csv"));
header = bufferedReader.readLine();
headerList = header.split(",");
}
public void map(LongWritable key, Text value, Context context) throws IOException,InterruptedException {
String line = value.toString();
String[] args = line.split(",");
if(headerList.length == args.length && !header.equals(line))
{
String srcip = args[4];
String dstip = args[5];
String scountry = args[20];
String dcountry = args[22];
Text sourceIP = new Text();
Text sourceCountry = new Text();
Text destIP = new Text();
Text destCountry= new Text();
if(!scountry.equals(""))
{
sourceIP.set(srcip);
sourceCountry.set(scountry);
context.write(sourceCountry,sourceIP);
}
if(!dcountry.equals(""))
{
destIP.set(dstip);
destCountry.set(dcountry);
context.write(destCountry,destIP);
}
暂无答案!
目前还没有任何答案,快来回答吧!