简体   繁体   中英

Properties-File won't get recognised!

So, I just wanted to use properties-files again, but currently I am just not able to load them! I've already wasted 1h of work just to get this working, but somehow I couldnt. My problem is similar to this one , but Java just doesn't get the file!

Here's my code:

package fast.ProfileManager;

import java.io.FileInputStream; import java.util.Properties;

import android.app.Activity; import android.content.Context; import android.net.wifi.WifiManager; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; import 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));

...

I've already tried to put an "/" infront of the filename, but it didnt work either.

Here's my Project-Directory:

在此输入图像描述

I'm getting an IOException on the line "properties.load ... "

Check out this introduction to using/accessing properties files in Android.

Based on that link, put the properties file in the /assets folder and use the following code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM