尝试访问资产文件夹中的子文件夹 [英] Trying to access sub folders in assets folder

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

问题描述

我的资产文件夹中有一个子文件夹树..我正在尝试访问该目录中的pdf..网址如下

my assets folder has a tree of sub folders.. i am trying to access a pdf in that directory .. the url is as follows

url = QP/28/28/mth.pdf

完整目录如下

ful directory = file:///data/data/com.example.testqstn/files/QP/28/28/mth.pdf

我已经使用以下代码访问了路径

i have accessed the path using the following code

intent.setDataAndType(Uri.parse("file://" + getApplicationContext().getFilesDir()
       + "/"+url), "application/pdf");
startActivity(intent);
     finish();

我没有收到任何错误消息,但pdf无法打开..当不使用子文件夹时,而pdf仅出现在资产文件夹中..则pdf可以正确打开. 那么到底是什么问题呢???

i am not getting any error msgs but the pdf is not opening.. when the sub folders are not used, and the pdf's are just present in the asset folder.. then the pdf opens correctly.. so what exactly is the problem???

并且日志猫未显示任何错误.

and the log cat is not displaying any error..

推荐答案

已解决

SOLVED

这真的很简单. 要访问资产文件夹中的子文件夹,您需要执行以下操作.

it was really simple.. to access the sub folders in assets folder you would need the following..

第一次通过文件名访问文件.

1st access the file by its file name..

    File file = new File(getFilesDir(), fname);

第二次尝试打开文件时,同时使用文件名和文件的网址

2nd while attempting to open the file use both file name and the url to the file

    in = assetManager.open(url+fname);

意图中的第3个仅使用文件名..(我使用了整个路径)

3rd in the intent use only the file name..(i was using the entire path)

    intent.setDataAndType(
        Uri.parse("file://" + getFilesDir() + "/"+fname),
        "application/pdf");

这篇关于尝试访问资产文件夹中的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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