Как создать текстовый файл в каталоге, который я создал (Android External Storage) - PullRequest
1 голос
/ 15 июня 2019

Я хочу создать 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 голосов
/ 15 июня 2019

как показано ниже:

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

  }


 }
...