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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With