如何编写其他应用程序可读的文件?
我的应用程序创建一个文本文件。我希望用户能够轻松访问这些文件。我将这个文本文件写入 SD 卡上。我想允许用户使用其他程序编辑该文件。
我使用文件资源管理器看到这些文件,但使用文件管理器看不到。
String extPath = Environment.getExternalStorageDirectory().getAbsolutePath();
try{
String pathPrefix = extPath + "/Android/data/" + getApplication().getPackageName() + "/cache/";
//File extPathFile = getExternalFilesDir(pathPrefix+FileName);
Log.d("TAG", "pathPrefix="+pathPrefix);
Log.d("TAG", "FileName="+FileName);
File file = new File(pathPrefix, FileName+".txt");
if(file.exists()){
Log.d("TAG", "File("+pathPrefix+FileName+")exist");
};
OutputStreamWriter outStream =
new OutputStreamWriter(new FileOutputStream(file));
日志猫:
01-22 14:26:15.834: D/TAG(14290): pathPrefix=/mnt/sdcard/Android/data/mast.avalons/cache/
01-22 14:26:15.834: D/TAG(14290): FileName=S000004_21-10-2011
01-22 14:26:16.044: D/TAG(14290): java.io.FileNotFoundException: /mnt/sdcard/Android/data/mast.avalons/cache/S000004_21-10-2011.txt (No such file or directory)
谢谢!
My application creates a text file. I want that users to have easy access to these files. I write this text file them on the sdcard. I want to allow users to edit the file with other programs.
I see these files using the File Explorer, but I can not see using file manager.
String extPath = Environment.getExternalStorageDirectory().getAbsolutePath();
try{
String pathPrefix = extPath + "/Android/data/" + getApplication().getPackageName() + "/cache/";
//File extPathFile = getExternalFilesDir(pathPrefix+FileName);
Log.d("TAG", "pathPrefix="+pathPrefix);
Log.d("TAG", "FileName="+FileName);
File file = new File(pathPrefix, FileName+".txt");
if(file.exists()){
Log.d("TAG", "File("+pathPrefix+FileName+")exist");
};
OutputStreamWriter outStream =
new OutputStreamWriter(new FileOutputStream(file));
Logcat:
01-22 14:26:15.834: D/TAG(14290): pathPrefix=/mnt/sdcard/Android/data/mast.avalons/cache/
01-22 14:26:15.834: D/TAG(14290): FileName=S000004_21-10-2011
01-22 14:26:16.044: D/TAG(14290): java.io.FileNotFoundException: /mnt/sdcard/Android/data/mast.avalons/cache/S000004_21-10-2011.txt (No such file or directory)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该创建中间目录:
I think you should create intermediate directories :