简体   繁体   English

我可以使用直接文件路径来访问存储在应用程序特定存储中的文件吗?

[英]Can I use direct file paths to access files stored in app specific storage?

I have an app where I capture/download images and store them to the app specific storage using:我有一个应用程序,我可以使用以下方法捕获/下载图像并将它们存储到应用程序特定的存储中:

File fileToSave = new File(getApplicationContext().getExternalFilesDir(
                        Environment.DIRECTORY_PICTURES), "filename");

Then, I save the absolute path to the file in the db using:然后,我使用以下命令将绝对路径保存到数据库中的文件:

saveToDb(fileToSave.getAbsolutePath())

My question is, will I be able to access the file later using this absolute path?我的问题是,我以后能否使用此绝对路径访问该文件?

File file = new File(savedAbsolutePath);

Is this the best practice?这是最佳做法吗?

will I be able to access the file later using this absolute path?我以后可以使用此绝对路径访问该文件吗?

Yes, assuming the user did not delete it or something.是的,假设用户没有删除它或其他东西。

Is this the best practice?这是最佳做法吗?

If you want the user to have some ability to access the content independently of your app, using getExternalFilesDir() is a fine choice.如果您希望用户能够独立于您的应用访问内容,那么使用getExternalFilesDir()是一个不错的选择。

If you do not want the user to have independent access to the content, you could use getFilesDir() instead.如果您不希望用户独立访问内容,则可以改用getFilesDir()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法访问存储在文件数组中的一系列文件 - I can't access a series of files stored in in a File Array 如何在外部应用程序 android 中打开存储在应用程序特定存储中的文件? - How open file stored in app specific storage in external app android? 如何访问通过App Engine应用存储的文件 - How to access files stored with App Engine app 如何找到存储在手机内部存储器中的 all.mp3 文件? - How can I find all .mp3 files stored on the internal storage of my phone? 无法访问内部存储中的文件 - Can't access files in the internal storage 如何使用SQLite直接访问文件中的特定记录? 在LibGDX中 - How to get direct access to specific record in file with SQLite? in LibGDX 我可以使用 PageFactory.initElements 创建 object 而 WebDriver 还没有直接(还)到存储 WebElements 的页面吗 - Can i use PageFactory.initElements to create an object while WebDriver isn't direct (yet) to the page where the WebElements are stored 如何在Java中设计和接口(OOP类型),以便我可以使用直接数据库访问或使用Web服务? - How do I Design and Interface (OOP kind) in Java so that I can either use direct database access or use web services? 如何防止Android应用程序中使用的文件的直接URL访问? - How to prevent direct URL access of a file which is used in an Android app? 如何在Spring应用程序中的特定文件夹中获取文件路径列表 - How to get a list of file paths in a specific folder in Spring app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM