带有子文件夹的 Android 资产

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3033902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:23:58  来源:igfitidea点击:

Android Assets with sub folders

androidassets

提问by Ian Vink

InputStream myInput = myContext.getAssets().open("MyFolder/" + "MyFile.db3");

I have a file in the assets folder in a sub folder as above. It doesn't get the file though, is there a special way to specify a sub folder in the assets folder?

我在上面的子文件夹中的资产文件夹中有一个文件。但是它没有获取文件,是否有一种特殊的方法可以在资产文件夹中指定一个子文件夹?

Ian

伊恩

回答by yanchenko

Edit: was wrong about subfolders.
This code works just fine on 1.5 (for a file sample.txtplaced under subfolder in assets):

编辑:关于子文件夹是错误的。
此代码在 1.5 上运行良好(对于sample.txt放置在sub文件夹下的文件assets):

InputStream is = getAssets().open("sub/sample.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = br.readLine()) != null) {
    Log.e("wtf", line);
}
br.close();

Are you sure you've got the names right?

你确定你的名字正确吗?

回答by Spark

"MyFolder/" + "MyFile.db3"

A filename for files added to the assets folder must be in lowercase letter. so,a filename such as MyFolder and Myfile.db3 is invalid. Rename them to "myfolder" and "myfile.db3",then everything will be fine.

添加到资产文件夹的文件的文件名必须是小写字母。因此,诸如 MyFolder 和 Myfile.db3 之类的文件名无效。将它们重命名为“myfolder”和“myfile.db3”,然后一切都会好起来的。

回答by CalloRico

Is your asset file over 1 MB?

您的资产文件是否超过 1 MB?

I notice that I get the same odd, empty IOException if I try to open an asset that is over this size. The fact that it is in a subfolder could be a red herring. I'm trying to open a large text file so I can workaround this limit by splitting it up. Can you do something similar with your .db3 file?

我注意到如果我尝试打开超过这个大小的资产,我会得到同样奇怪的空 IOException。它位于子文件夹中的事实可能是一个红鲱鱼。我正在尝试打开一个大文本文件,以便我可以通过拆分来解决此限制。你能用你的 .db3 文件做类似的事情吗?

回答by Holger.Buick

I had a similar issue: Changed the subfolder name from "mp3" to "mpthree" and the files were found.

我有一个类似的问题:将子文件夹名称从“ mp3”更改为“ mpthree”并找到了文件。