Java 大数据 取出两列不同的值 生成到文本中

[size=large]项目前端商城的订单和后端服务的订单有差异,金额比对不上,Excel又不会用,只有自己写代码了。[/size]



public class FindNotSameFieldUtil {
private static final String encoding="GBK";
private static final String n = System.getProperty("line.separator");

public static void main(String[] args) throws Exception {
Map<String,String> map1 = new HashMap<String, String>();
String filePath1 = "c://05HX.txt";
Map<String,String> map2 = new HashMap<String, String>();
String filePath2 = "c://05SC.txt";

ReadTxt(filePath1,map1);
ReadTxt(filePath2,map2);

for (Map.Entry<String,String> entry : map2.entrySet()) {
if(map1.containsKey(entry.getKey())){
map1.remove(entry.getKey());
}
}
String filePath3 = "c://05DIFF.txt";
GenerateFile(map1,filePath3);

}
/**
* 把读取到的字段放入到map中剔除重复字段
* @param filePath
* @param map
* @throws Exception
*/
private static void ReadTxt(String filePath,Map map) throws Exception{
File file=new File(filePath);
if(file.isFile() && file.exists()){ //判断文件是否存在
InputStreamReader read = new InputStreamReader(new FileInputStream(file),encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while((lineTxt = bufferedReader.readLine()) != null){
map.put(lineTxt, "");
}
read.close();
}
}
/**
* 把map的key拿出来 生成到文本中去
* @param map
* @param filePath
* @throws Exception
*/
private static void GenerateFile(Map<String,String> map,String filePath) throws Exception{
BufferedWriter bw= new BufferedWriter(new FileWriter(filePath));
StringBuffer sb = new StringBuffer();
for (Map.Entry<String,String> entry : map.entrySet()) {
sb.append(entry.getKey() + n);
}
bw.append(sb.toString());
bw.flush();bw.close();
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值