屬性文件對比工具類

/*
This file is part of BORG.

BORG is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

BORG is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with BORG; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Copyright 2003 by Mike Berger
*/

package net.sf.borg.ui;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Properties;

/**
*屬性文件對比工具類
*Author:liuwang
*Creation time:2012年12月17日10:21
*/
public class PropertiesUtil {
public static void main(String[] args) throws FileNotFoundException,
IOException {
String filePath = "c:\\borg_resource.properties";
String filePath2 = "c:\\borg_resource_zh_CN.properties";
distinct(filePath2, filePath);
}

/**
* 對比差異,後者獨有屬性
*/
public static void distinct(String filePath, String filePath2) {
File file = new File(filePath);
File file2 = new File(filePath2);
FileInputStream fis = null;
FileInputStream fis2 = null;
try {
fis = new FileInputStream(file);
Properties prop = new Properties();
prop.load(fis);
fis2 = new FileInputStream(file2);
Properties prop2 = new Properties();
prop2.load(fis2);
// ** 循環讀取英文屬性文件的key,去中文屬性文件中查找,如果沒找到就輸出*//*
Iterator itr2 = prop2.entrySet().iterator();
while (itr2.hasNext()) {
Entry e2 = (Entry) itr2.next();
Iterator itr = prop.entrySet().iterator();
Boolean flag = false;
while (itr.hasNext()) {
Entry e = (Entry) itr.next();
if (e2.getKey().equals(e.getKey())) {
// System.out.println("相同的key"+e2.getKey());
flag = true;
break;
} else {
}

}
if (!flag)
System.out.println(e2.getKey() + " = " + e2.getValue());
}
sumOfPro(filePath);
sumOfPro(filePath2);

// fos2 = new FileOutputStream(file2);
// prop.store(fos2, null);
} catch (Exception e) { // TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
fis.close();
fis2.close();
// fos2.close();
} catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}
}

/**
* 總屬性個數
* @param filePath
* @throws FileNotFoundException
* @throws IOException
*/
public static void sumOfPro(String filePath) throws FileNotFoundException,
IOException {
Properties p = new Properties();
p.load(new FileInputStream(new File(filePath)));
Iterator itr = p.entrySet().iterator();
int i = 0;
while (itr.hasNext()) {
Entry e = (Entry) itr.next();
i++;
// System.out.println(e.getKey());
}
System.out.println(filePath + "文件屬性總數爲:" + i);
}
/**
* 運行轉碼
* @return
*/
public static String toAscii() {
try {
Runtime.getRuntime()
.exec("cmd.exe /c start d:\\java\\jdk1.6\\bin\\native2ascii.exe");

} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章