使用Kotlin创建一个新的目录,Mkdir()不起作用
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() } } }
- Kotlin kotlinClass.class.getName()不能返回包名,而只能返回简单的类名
- 在kotlin中测试容器的项目类型
- 在OnLongPress Android中处理ACTION_UP
- 如何用kotlin 1.1.0 kotlinx-coroutines-core lib的功能替换Anko的doAsync,uiThread?
- AndroidStudio / Kotlin – 未解决的参考:ReadWriteProperty – Kotlin版本1.0.0-beta-1038
- Android Room:查询中的每个绑定变量都必须具有匹配的方法
- 为什么有一个类存在的NoClassDefFoundError?
- 如何在Android中添加对普通Java Lib的Kotlin支持?
- RxJava和Kotlin的花括号和正常括号有什么区别?