繁体   English   中英

如何在我创建的目录内创建文本文件(Android外部存储)

[英]How to create a text file inside the directory that I have created (Android External Storage)

我想在使用代码创建的folder内创建一个text file 我创建了RegUp 现在,我需要在RegUp文件夹中创建一个text file


我用来创建文件夹的代码:

if(isExternalStorageWritable())
{
      String albumName = "RegUP";
      String fileName = "file.txt";

      File file = new File(Environment.getExternalStorageDirectory(), albumName);

      if (!file.mkdirs())
      {
            Log.e("msg", "Directory not created");
      }
      else
      {
            Log.e("msg", "Directory created");

      }
}

如下所示:

if(isExternalStorageWritable())
{
  String albumName = "RegUP";
  String fileName = "file.txt";

  File file = new File(Environment.getExternalStorageDirectory(), albumName);

  if (!file.mkdirs())
  {
        Log.e("msg", "Directory not created");
  }
  else
  {
        File new_File=new File(file.getPath()+"/"+fileName);//you can now write to this file
        Log.e("msg", "Directory created");

  }


 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM