递归遍历文件夹&读取ini文件&获取ini的全部key

遍历文件夹

public class Test{ public static void showAllFiles(File dir) throws Exception { File[] fs = dir.listFiles(); for (int i = 0; i < fs.length; i++) { System.out.println(fs[i].getAbsolutePath()); if (fs[i].isDirectory()) { try { showAllFiles(fs[i]); } catch (Exception e) { } } } } public static void main(String[] args) { // TODO Auto-generated method stub File root = new File("c:"); try { showAllFiles(root); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 

上面一个是转自百度贴

http://zhidao.baidu.com/question/86530592

 

 读取ini文件获取相关key的value值

public static String ReadINI(String FilePath, String Key) { String Value = ""; File file = new File(FilePath); try { FileReader filereader = new FileReader(file); Properties p = new Properties(); try { p.load(filereader); Value = p.getProperty(Key); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return Value; } 

获取ini文件的所有key

public static Set<String> ReadINIforKeysSet(String FilePath) { Set<String> set = null; File file = new File(FilePath); try { FileReader filereader = new FileReader(file); Properties p = new Properties(); try { p.load(filereader); set = (Set<String>) p.stringPropertyNames(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return set; }

你可能感兴趣的:(exception,String,properties,File,Class,ini)