zoukankan      html  css  js  c++  java
  • 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.");
              }
        }


  • 相关阅读:
    MongoDB的安装与简单使用
    [SCOI2008]天平
    [ZJOI2008]树的统计
    [HEOI2015]兔子与樱花
    [HAOI2006]l旅行
    [ZJOI2008]泡泡堂BNB
    [ZJOI2007]时态同步
    [SCOI2005]栅栏
    [SCOI2008]着色方案
    [SCOI2005]互不侵犯King
  • 原文地址:https://www.cnblogs.com/kevinGao/p/2426890.html
Copyright © 2011-2022 走看看