日期:2014-05-20 浏览次数:20831 次
public static void main(String[] args) throws Exception {
String str="";
String result="";
Map map=returnMap("D:\\old.csv");
FileReader fr=new FileReader("D:\\new.csv");
BufferedReader br=new BufferedReader(fr);
while((str=br.readLine())!=null){
String s[]=str.split(",");
if(map.get(s[4])!=null){
}
result=result+str+"\n";
}
write(result);
}
public static Map returnMap(String file) throws Exception{
FileReader fr=new FileReader(file);
BufferedReader br=new BufferedReader(fr);
String str="";
Map<String,String> map=new HashMap<String, String>();
while((str=br.readLine())!=null){
String s[]=str.split(",");
String sku=s[4];
String carrier=s[16];
map.put(sku, carrier);
}
return map;
}
public static void write(String result) throws Exception{
FileWriter fw=new FileWriter("D:\\new.csv");
PrintWriter pw=new PrintWriter(fw);
pw.write(result);
pw.flush();
}
public class Test1 {
public static void main(String[] args) throws Exception {
String str="";
String result="";
Map map=returnMap("D:\\old.csv");
//读取一份新的文件,判断每一行
FileReader fr=new FileReader("D:\\new.csv");
BufferedReader br=new BufferedReader(fr);
while((str=br.readLine())!=null){
String s[]=str.split(",");
if(map.get(s[4])!=null){
result=result+str+map.get(s[4])+"\n";
}
}
write(result);
}
//读取一份原版文件,然后把其中的sku和carrier制作成一个map。并返回
public static Map returnMap(String file) throws Exception{
FileReader fr=new FileReader(file);
BufferedReader br=new BufferedReader(fr);
String str="";
Map<String,String> map=new HashMap<String, String>();
while((str=br.readLine())!=null){
String s[]=str.split(",");
String sku=s[4];
String carrier=s[16];
map.put(sku, carrier);
}
return map;
}
public static void write(String result) throws Exception{
FileWriter fw=new FileWriter("D:\\test.csv");
PrintWriter pw=new PrintWriter(fw);
pw.write(result);
pw.flush();
}
}