Android中写文本文件的方法
?????? 下面是我在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.");
?? ??? ?? }
?? ?}
轉載于:https://www.cnblogs.com/kevinGao/archive/2012/02/29/2426890.html
總結
以上是生活随笔為你收集整理的Android中写文本文件的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拉卡拉易分期怎么样?期数、额度、放款速度
- 下一篇: 工商银行信用卡有效期有几年?有效期到了怎