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

时间:2019-06-15 10:03:27

标签: java android android-external-storage

我想在text file设备的外部存储器中使用代码创建的folder内创建android。使用我的代码,我创建了folder。现在,我需要知道如何在相同的text file中创建一个folder


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

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");

      }
}

1 个答案:

答案 0 :(得分:0)

如下所示:

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");

  }


 }