【问题标题】:How to create a text file inside the directory that I have created (Android External Storage)如何在我创建的目录中创建文本文件(Android 外部存储)
【发布时间】:2019-06-15 10:03:27
【问题描述】:

我想在我使用代码创建的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");

      }
}

【问题讨论】:

  • 以上代码有什么问题?
  • @KaranMer 没问题。这是用于创建名为RegUP 的文件夹的代码。我只是提供了代码来展示我是如何创建文件夹的。
  • 你经历过这个吗:stackoverflow.com/questions/8152125/…
  • @MiniChip 不,我没有。刚查了那个帖子。谢谢。

标签: java android android-external-storage


【解决方案1】:

如下:

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

  }


 }

【讨论】:

    猜你喜欢
    • 2014-09-07
    • 1970-01-01
    • 2020-12-22
    • 2017-12-28
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多