我有一个应用程序,让我通过文件浏览器选择一个文件(该文件存储在SD上),然后读取它。
我想修改它,因此它将文件直接放入应用程序并从“内部”读取文件。 我必须把文件放到项目中? 我该如何访问它?
I have an application that make me choose a file through a file explorer(the file is stored on the sd), and then reads it.
I want to modify it, so it has the file directly into the app and reads the file from "inside". Where I have to put the file into the project? How can I access it?
最满意答案
是的,您可以将您的文件放入/ assets文件夹,并检索如下:
AssetManager assetManager = getAssets(); InputStream instream = assetManager.open("file.txt");或res / raw文件夹:
InputStream raw = getResources().openRawResource(R.raw.file);如果要修改它,您只能将文件写入外部存储(例如sdcard)或内部存储(在应用程序文件夹data/data/package_name/ )。 如果将文件存储到外部存储器中,它将一直存在,直到用户手动或以编程方式删除该文件。 但是,如果将此文件存储到内部存储中,则在用户删除应用程序或清除应用程序缓存时将删除该文件。
Yes, you can put your file into /assets folder, and retrieve as follows:
AssetManager assetManager = getAssets(); InputStream instream = assetManager.open("file.txt");or res/raw folder:
InputStream raw = getResources().openRawResource(R.raw.file);If you want to modify it, you'll be able only to write a file into External storage (e.g. sdcard), or into Internal storage (under your application folder data/data/package_name/). If you store your file into External storage it will persist until user manually or programmatically deletes the file. But if you store this file into Internal storage, it will be deleted if user deletes an app, or clear an application cache.
更多推荐
发布评论