1

How to create folder (for example in the folder "Documents" in my phone), in this folder create the file and write data in this file? I have a code. But I am not shure that I do my file path is right. I want create folder and file not at SD card / I want do it in the device memory.

var filePath = File(Environment.DIRECTORY_DOCUMENTS + "myFolder/myFile.txt")
                filePath.mkdirs()
          
                try {
                    var outPut = FileOutputStream(filePath)
                    outPut.write("Hello")
                    outPut.close()
                } catch (e: Exception) {
                    e.printStackTrace();
                }
Julia
  • 369
  • 2
  • 12
  • 3
    This question has been asked a lot and you will find a lot of similar questions when you use Stack Overflow's search function. – Mr. Robot Dec 16 '20 at 10:55

1 Answers1

0

Duplicate. This question answers how to create a file on the internal memory: Android: how to write a file to internal storage. And this question answers how to create a folder on the internal memory: How to create a folder in the phone memory (not SD card) in Android?.

Mr. Robot
  • 397
  • 1
  • 14