Android上Assets文件夹中的ResourceBundle [英] ResourceBundle on Android in Assets folder
问题描述
我目前在纯Java程序中使用ResourceBundles.现在,我想在Android应用程序中使用相同的文件.当放置文件时,它可以按预期工作.在/sdcard/.有没有一种方法可以直接从已知的android文件夹结构中加载它们?例如从资产中手动解决它们到sdcard?
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?
这在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);
此网址不适用于assests文件夹:
This url doesn´t work for the assests folder:
urls = new URL[]{new URL("file:///android_asset/test/")};
感谢您的帮助.
推荐答案
尝试在此路径src/main/resources
上创建resources
文件夹,然后在Android上使用ResourceBundle
从此处放置或获取文件.
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.
对我有用.
这篇关于Android上Assets文件夹中的ResourceBundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!