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(); } }
Java 大数据 取出两列不同的值 生成到文本中
项目前端商城的订单和后端服务的订单有差异,金额比对不上,Excel又不会用,只有自己写代码了。
猜你喜欢
转载自lovejavah123.iteye.com/blog/2306049
今日推荐
周排行