android - 资产文件路径 [英] android - assets files path

查看:32
本文介绍了android - 资产文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 android studio 中遇到资产文件路径问题.我想在资产文件夹中给出文本文件的路径,如下所示:

I have problem with assets files path in android studio. I want give path of text file in assets folder like below:

File f = new File(path_of_text_file_in_assets);
fw = new FileWriter(f);
bw = new BufferedWriter(fw);

我在这段代码的其他部分也有类似的问题,我想在资产的子文件夹中给出图像的路径,如下所示:

I have similar problem in other parts of this code, that I want give the path of images in subfolder of assets like below:

File ff = new File(path_of_image_in_subfolder_of_assets);
StringBuilder sbFeatureX = uniformQuantization( ff );

我在互联网上搜索了很多,但没有答案!!

I have searched a lot on the internet, but no answer!!

注意:请考虑我不想打开文件,所以 getAssets().open() 不是我的答案!

Note: please consider I don't want open the file, so the getAssets().open() is not my answer!

推荐答案

您不能对资产中的文件使用 File 类.文件用于文件系统中的文件.

You cannot use the File class for files in assets. File is for files in the file system.

处理资产文件的唯一方法确实是使用输入流的 .open() 函数.

The only way to handle assets files is indeed with that .open() function using the input stream.

此外,您无法写入资产中的文件.它们在那里只读.

Further you cannot write to files in assets. They are read only there.

FileWriter 和 FileReader 都不能使用.

FileWriter and FileReader both cannot be used.

这篇关于android - 资产文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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