下面是我在Android开发中,一个写文本文件的方法,代码如下:
//将字符串写入到文本文件中
public static void WriteTxtFile(String strcontent,String strFilePath)
{
//每次写入时,都换行写
String strContent=strcontent+"\n";
try {
File file = new File(strFilePath);
if (!file.exists()) {
Log.d("TestFile", "Create the file:" + strFilePath);
file.createNewFile();
}
RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(file.length());
raf.write(strContent.getBytes());
raf.close();
} catch (Exception e) {
Log.e("TestFile", "Error on write File.");
}
}
本文介绍了一个在Android开发中用于将字符串写入文本文件的实用方法,包括创建文件、确保文件存在以及如何实现换行写入。
806

被折叠的 条评论
为什么被折叠?



