开发者

Properties-File won't get recognised!

开发者 https://www.devze.com 2023-03-15 11:09 出处:网络
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 t

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:

Properties-File won't get recognised!

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号