写在Android的文本文件资源 [英] Write to a Text File Resource in Android
问题描述
有谁知道如何使用类似的资源写入一个文本文件中的Android:
R.raw.my_text_file
我只是在寻找的东西干净和简单。我GOOGLE了四周,但我发现这个例子没有工作。我试图code。使用Android的文档,但不能换我的头周围...
感谢
编辑:
我已经使用了Android文档创建此code。日志打印出1和9和code之间跳过一切,什么都不做:
{尝试
字符串文件名=RES /生/ my_text_file.txt
串串; Log.v(TAG,1);
FOS的FileOutputStream = openFileOutput(文件名,Context.MODE_PRIVATE);
Log.v(TAG,2); 的for(int i = 0; I<则为list.size();我++){
Log.v(TAG,3);
尝试{
Log.v(TAG,4);
串= I + - + list.get(ⅰ);
fos.write(string.getBytes());
}赶上(例外五){
Log.v(TAG,5);
}
Log.v(TAG,6);
}
Log.v(TAG,7);
fos.close();
Log.v(TAG,8);
}赶上(例外五){ }
Log.v(TAG,9);
有谁知道如何使用资源写入一个文本文件中的Android
块引用>资源是只读在运行时,不能写入
Does anyone know how to write to a text file in Android using a resource like:
R.raw.my_text_file
I'm just looking for something clean and simple. I've Googled around but the examples I found didn't work. I tried to code using the Android docs but couldn't wrap my head around it...
Thanks
EDIT:
I've used the Android docs to create this code. The logs print out "1" and "9" and the code skips everything in between and does nothing:
try { String filename = "res/raw/my_text_file.txt"; String string; Log.v(TAG, "1"); FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE); Log.v(TAG, "2"); for (int i = 0; i < list.size(); i++) { Log.v(TAG, "3"); try { Log.v(TAG, "4"); string = i + " - " + list.get(i); fos.write(string.getBytes()); } catch (Exception e) { Log.v(TAG, "5"); } Log.v(TAG, "6"); } Log.v(TAG, "7"); fos.close(); Log.v(TAG, "8"); } catch (Exception e) { } Log.v(TAG, "9");
解决方案Does anyone know how to write to a text file in Android using a resource
Resources are read-only at runtime and cannot be written to.
这篇关于写在Android的文本文件资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!