Creating a new directory using Kotlin, Mkdir() doesn't work

前端 未结 2 1482
梦毁少年i
梦毁少年i 2021-02-14 04:58
var filename = \"blesson.txt\"
var wallpaperDirectory = File(\"/sdcard/Wallpaper\")
 wallpaperDirectory.mkdirs()
val outputFile = File(wallpaperDirectory, filename)
val          


        
2条回答
  •  [愿得一人]
    2021-02-14 05:26

    You can also use also to do this:

    File("path_to_file").also {
                                  file -> file.parentFile.mkdirs()
                              }.writeBytes(bytes)
    

提交回复
热议问题