java - 属性文件不会被识别!

标签 java android file properties

所以,我只是想再次使用属性文件,但目前我无法加载它们!我已经浪费了 1 小时的工作只是为了让它工作,但不知何故我做不到。我的问题类似于 this one , 但 Java 就是不获取文件!

这是我的代码:

快速打包.ProfileManager;

导入java.io.FileInputStream; 导入 java.util.Properties;

导入android.app.Activity; 导入 android.content.Context; 导入 android.net.wifi.WifiManager; 导入 android.os.Bundle; 导入 android.view.View; 导入 android.view.View.OnClickListener; 导入 android.widget.CheckBox; 导入 android.widget.Toast;

public class PMMain extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String defaultProfileProperties = "defaultProfile.properties";
        Properties properties = new Properties();
        properties.load(new FileInputStream(defaultProfileProperties));

...

我已经试过在文件名前加一个“/”,但也没用。

这是我的项目目录:

enter image description here

我在“properties.load ...”行收到 IOException

最佳答案

查看 this introduction在 Android 中使用/访问属性文件。

基于该链接,将属性文件放入/assets 文件夹并使用以下代码:

// Read from the /assets directory
try {
    InputStream inputStream = assetManager.open("defaultProfile.properties"");
    Properties properties = new Properties();
    properties.load(inputStream);
    System.out.println("The properties are now loaded");
    System.out.println("properties: " + properties);
} catch (IOException e) {
    System.err.println("Failed to open microlog property file");
    e.printStackTrace();
}

关于java - 属性文件不会被识别!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6471131/

相关文章:

java - 在 Java 中合并(Concat)多个 JSONObject

java - 将用户输入文本复制到输出文本文件(java)

java - ArrayList元素拒绝被移除

java - Java 真的是按值传递对象吗?

java - jqgrid增加工具栏高度

java - 将字符串写入文件的最有效方法

c - C 程序停顿

java - 与线程模式混淆

android - Android 上的 SQL 客户端

Android Google map 服务导致构建错误