62,614
社区成员
发帖
与我相关
我的任务
分享
mport java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
public class Propertie {
/**
* @param args
*/
private String[] midObj = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
Propertie pt = new Propertie();
pt.getMinObj();
String[] test = pt.getAllKeys();
for(String p :test)
System.out.println(p);
}
public void getMinObj(){
File f = new File("phone.properties");
Properties pos = new Properties();
try {
pos.load(new FileInputStream(f));
Set<Object> s = pos.keySet();
Object[] pp = s.toArray();
midObj = new String[pp.length];
for(int j=0;j<pp.length;j++)
midObj[j] = String.valueOf(pp[j]);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.err.println("配置文件phone.properties找不到!!");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String[] getAllKeys(){
Vector<String> allKeys = new Vector<String>();
String[] selectKey = null;
for(int i=0;i<midObj.length;i++){
String everykey = midObj[i];
int firstPos = everykey.indexOf(".");
if(!allKeys.contains(everykey.substring(0,firstPos)))
allKeys.addElement(everykey.substring(0,firstPos));
}
/*for(int j=0;j<allKeys.size();j++)
for(int k=j+1;k<allKeys.size();k++){
if(allKeys.get(j).equals(allKeys.get(k))){
allKeys.remove(k);
}
System.out.println(allKeys.size());
}*/
selectKey = new String[allKeys.size()];
selectKey = allKeys.toArray(selectKey);
return selectKey;
}
}