1. 程式人生 > >自己編寫讀取配置檔案的資訊的方法

自己編寫讀取配置檔案的資訊的方法

在這裡插入圖片描述結果:
在這裡插入圖片描述

程式碼:

public static void main(String[] args) {
    //自己編寫的讀取配置檔案的方法
    InputStream inputStream = FtpConfig.class.getResourceAsStream("/ftp.properties");
    Properties properties =new Properties();//Map介面的實現類
    try {
        properties.load(inputStream);
        //System.out.println(properties.get("mybatis.typeAliasesPackage")+"............");
Set<Object> objects = properties.keySet();//返回map的所有key //objects.iterator(); 遍歷map至少要知道2種方法 for (Object object : objects) { System.out.println("key:"+object+",value:"+properties.get(object)); } } catch (IOException e) { e.printStackTrace();
} }