当前位置: 代码迷 >> Web前端 >> 流方式读写资料 去处Proprey文件重复项
  详细解决方案

流方式读写资料 去处Proprey文件重复项

热度:147   发布时间:2012-08-26 16:48:06.0
流方式读写文件 去处Proprey文件重复项
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();

	}

}

?

  相关解决方案