Android上Assets文件夹中的ResourceBundle [英] ResourceBundle on Android in Assets folder

查看:96
本文介绍了Android上Assets文件夹中的ResourceBundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在纯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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆