【问题标题】:Properties-File won't get recognised!无法识别属性文件!
【发布时间】:2011-06-24 16:54:40
【问题描述】:

所以,我只是想再次使用属性文件,但目前我无法加载它们!我已经浪费了 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));

...

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

这是我的项目目录:

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

【问题讨论】:

    标签: java android file properties


    【解决方案1】:

    查看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();
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-14
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      • 1970-01-01
      相关资源
      最近更新 更多