package com.cbuy; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.TreeMap; import java.util.Map.Entry; public class RemoveDuplication { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Map mapkey = new TreeMap (); Properties fp1 = new Properties(); // boot root fp1.load(RemoveDuplicate.class.getClassLoader().getResourceAsStream("test.properties")); Enumeration e3 = fp1.keys(); int jj=0; while(e3.hasMoreElements()){ jj++; mapkey.put(jj,e3.nextElement()); //System.out.println(e3.nextElement()); } Map<String, Integer> keyfreqs = new HashMap<String, Integer>(); Iterator<String> it = mapkey.keySet().iterator(); while(it.hasNext()){ System.out.println("==="+mapkey.get(it.next())); } if(mapkey.containsValue("res_bu_landing_paras")){ System.out.println("****"); } BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("D:/soursefile.txt"),"GB2312")); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:/targetfile.txt"),"GB2312")); String data = null; int i = 0; while((data = br.readLine())!=null) { //System.out.println(data); String ongLine=data; if(ongLine.indexOf("=")>0&& !ongLine.substring(0, 1).endsWith("#")){ i++; String font=""; String back=""; font=ongLine.substring(0, ongLine.indexOf("=")); back=ongLine.substring(ongLine.indexOf("=")+1, ongLine.length()); font=font.trim(); back=back.trim(); if(mapkey.containsValue(font)){ }else{ bw.write(data); } //System.out.println(font); } // System.out.println(new String(data.getBytes("GBK"))); bw.newLine(); } br.close(); bw.close(); } }
?