[英]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.