转换imei号

package lunzi.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ConvertImei {

/**
* @param args
*/

public static void main(String[] args) {
convert(args);
}

private static void convert(String[] args) {
System.out.println(
"--------convetImei start----------------");
if (args.length<=0) {
return;
}

System.out.println(
"--------convetImei file="+args[0]+"----------------");

FileReader fr = null;
BufferedReader br = null;
FileWriter fw = null;
BufferedWriter bw = null;
Map<String,String> map = new HashMap<String,String>();
try {
fr = new FileReader(args[0]);
br = new BufferedReader(fr);
String line = null;
String[] filedArr = null;
String imei = null;
StringBuffer sb = new StringBuffer();
String txt = null;
while((line=br.readLine()) != null) {
filedArr = line.split(
" ");
imei = filedArr[4];
if (!
"null".equals(imei)) {
if (!map.containsKey(imei)) {
map.put(imei, Encrypt.Dencrypt(imei,
""));
}
System.out.println(Encrypt.Dencrypt(imei,
""));
}
sb.append(line).append(
"\n");
}

txt = sb.toString();
for(Map.Entry<String, String> entry:map.entrySet()){
            txt = txt.replaceAll(entry.getKey(), entry.getValue());
            System.out.println(
"--------entry.getKey()=>"+entry.getKey()+"----------entry.getValue()=>"+entry.getValue()+"+------");
     }

fw = new FileWriter(args[0]);
bw = new BufferedWriter(fw);
bw.write(txt);
bw.flush();
System.out.println(
"--------convetImei succful----------------");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fw != null) {
fw.close();
}
if (bw != null) {
bw.close();
}

if (fr != null) {
fr.close();
}

if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(
"--------convetImei end----------------");
}

}

lunzi   2011-06-01 19:18:35 评论:1   阅读:523   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog