1

/raw にプロパティ ファイルを作成しましたが、ファイルを読み取っても問題ありません。

public static String readProperties(String filePath, String parameterKey) {
    String result = null;
    Properties pro = new Properties();
    try {
        pro.load(GlobalVariate.class.getResourceAsStream(filePath));
        // pro.load(GlobalVariate.class
        // .getResourceAsStream("/assets/config.properties"));
        result = pro.get(parameterKey).toString();

    } catch (IOException e) {
        System.out.println("load fail:" + e);
        e.printStackTrace();
    }
    return result;
}

しかし、私が書いたとき、ファイルパスが存在しないと言いました:

public void saveConfig(Context context, String file, Properties properties) {
    try {
        FileOutputStream s = new FileOutputStream(file, false);
        properties.store(s, "");
        System.out.println("write success!");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("write error:+" + e);
    }
}

saveConfig(this, "/assets/config.properties", prop);
4

1 に答える 1

1

書き込みプロパティ ファイルを /raw フォルダーに読み込みたいとおっしゃいましたが、ここでは assests フォルダーにファイルを書き込んでいるようです。だから変更する

/assests.config.properties

/raw/config.properties
于 2013-09-19T05:28:34.200 に答える