var filename = "blesson.txt"
var wallpaperDirectory = File("/sdcard/Wallpaper")
wallpaperDirectory.mkdirs()
val outputFile = File(wallpaperDirectory, filename)
val fos = FileOutputStream(outputFile)
我正在尝试使用 Kotlin 在 Android 设备上创建一个新目录,但是该函数mkdirs()
不起作用。
var filename = "blesson.txt"
var wallpaperDirectory = File(Environment.getExternalStorageDirectory().absolutePath)//("/sdcard/Wallpaper")
wall
val outputFile = File(wallpaperDirectory, filename)
val fos = FileOutputStream(outputFile)
我也尝试过,它没有创建新目录
欢迎任何帮助
这在 Kotlin 上完美运行
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var filename = "blesson.txt"
// create a File object for the parent directory
val wallpaperDirectory = File("/sdcard/Wallpaper/")
// have the object build the directory structure, if needed.
wallpaperDirectory.mkdirs()
// create a File object for the output file
val outputFile = File(wallpaperDirectory, filename)
// now attach the OutputStream to the file object, instead of a String representation
try {
val fos = FileOutputStream(outputFile)
} catch (e: FileNotFoundException) {
e.printStackTrace()
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)