use*_*595 5 android assets resourcebundle
我目前在纯Java程序中使用ResourceBundles。现在,我想在Android应用程序中使用相同的文件。当文件放置在例如/ sdcard /时,它可以按预期工作。有没有办法直接从已知的android文件夹结构中加载它们?例如从资产没有手动应对它们到SD卡?
这适用于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);
Run Code Online (Sandbox Code Playgroud)
该网址不适用于assests文件夹:
urls = new URL[]{new URL("file:///android_asset/test/")};
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
resources尝试在此路径上创建一个文件夹src/main/resources,然后在 Android 上使用从那里放置或获取文件ResourceBundle。
这个对我有用。