ResourceBundle on Android in Assets folder

前提是你 提交于 2019-12-10 15:32:45

问题


i´m currently useing ResourceBundles in a pure Java program. Now I want to use the same files inside of an Android app. It works as intended, when the file is placed e.g. at /sdcard/. Is there a way to load them directly from the known android folder structure? e.g. from assets wihtout manually coping them to the sdcard?

This works at the sdcard:

    File file = new File("/sdcard/");
    URL[] urls = new URL[0];
    try {
       urls = new URL[]{file.toURI().toURL()};

    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    ClassLoader loader = new URLClassLoader(urls);
    ResourceBundle rb = ResourceBundle.getBundle("test", Locale.DEFAULT, loader);

This url doesn´t work for the assests folder:

   urls = new URL[]{new URL("file:///android_asset/test/")};

Thanks for any help.


回答1:


Try creating a resources folder on this path src/main/resources and then put or get your files from there by using ResourceBundle on Android.

It works for me.



来源:https://stackoverflow.com/questions/26833226/resourcebundle-on-android-in-assets-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!