内部存储"文件的路径是无效的" [英] Internal Storage "the document path is not valid"

查看:131
本文介绍了内部存储"文件的路径是无效的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:文件路径无效

我要存储的PDF在内部存储器后,我想读它。

I want to store pdf in internal storage and after I want to read It.

我见过许多阙在这个网站,但没有帮助我。

I seen many que in this site but none help me out.

我的$ C $的Environment.getExternalStorageDirectory()C工作文件现在我用getCacheDir()的内部存储。

My code working file in Environment.getExternalStorageDirectory() now I used getCacheDir() for internal storage.

写PDF

 FileOutputStream fos = new FileOutputStream(file);
                fos.write(baf.toByteArray());
                fos.close();

文件写入完成后,我可以看到文件的缓存文件夹。

file write is completed , I can see file in cache folder.

对于阅读PDF

file = new File(getCacheDir()+ File.separator+fileName);

PackageManager packageManager = getPackageManager();
            Intent testIntent = new Intent(Intent.ACTION_VIEW);
            testIntent.setType("application/pdf");
            List list = packageManager.queryIntentActivities(testIntent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() > 0 && file.isFile()) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                Uri uri = Uri.fromFile(file);
                intent.setDataAndType(uri, "application/pdf");
                startActivity(intent);
            }

我遇到错误documenty路径无效

推荐答案

使用 getFilesDir()内部存储

公共抽象文件getFilesDir()

public abstract File getFilesDir ()

加在API级别1 返回的绝对路径在哪里与openFileOutput(字符串,INT)创建的文件都存储在文件系统的目录。

Added in API level 1 Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.

返回 返回目录保持应用程序文件的路径。 也可以看看 openFileOutput(字符串,INT) getFileStreamPath(字符串) GETDIR(字符串,INT)

Returns Returns the path of the directory holding application files. See Also openFileOutput(String, int) getFileStreamPath(String) getDir(String, int)

恩。

File yourFile = context.getFilesDir() + "/" + "file_name";

这里了解详细信息

这篇关于内部存储"文件的路径是无效的"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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