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

前端 未结 2 1130
挽巷
挽巷 2021-02-14 05:19
var filename = \"blesson.txt\"
var wallpaperDirectory = File(\"/sdcard/Wallpaper\")
 wallpaperDirectory.mkdirs()
val outputFile = File(wallpaperDirectory, filename)
val          


        
2条回答
  •  情深已故
    2021-02-14 05:32

    You can also use also to do this:

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

提交回复
热议问题