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

猜你喜欢

转载自blog.csdn.net/weixin_34112181/article/details/93286429