Kotlin File writeText appendText appendBytes readBytes readText

Kotlin File writeText appendText appendBytes readBytes readText

Kotlin 复制代码
import java.io.File

fun main(args: Array<String>) {
    val filePath = "./myfile.txt"

    val file = File(filePath)

    file.writeText("hello,") //如果原有文件有内容,将完全覆盖。
    file.appendText("world!") //在原文件尾部追加。
    file.appendBytes("2023 year".toByteArray()) //在原文件尾部追加。

    val bytes: ByteArray = file.readBytes()
    println(String(bytes))

    println(file.readText())
}

Kotlin Files readAllBytes readAllLines readString-CSDN博客Java把一个文件转化为byte字节数组 /** * 把一个文件转化为byte字节数组。try { File..._java文件转byte数组。Java把一个文件转化为byte字节数组_java文件转byte数组_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/132763802

相关推荐
来来走走1 小时前
Android开发(Kotlin) 扩展函数和运算符重载
android·开发语言·kotlin
wuwu_q1 小时前
用通俗易懂 + Android 开发实战的方式,详细讲解 Kotlin Flow 中的 retryWhen 操作符
android·开发语言·kotlin
li-jia-wei4 小时前
我在造一个编程语言,叫 Free
kotlin
Android-Flutter5 小时前
kotlin - 显示HDR图(heic格式),使用GainMap算法,速度从5秒提升到0.6秒
android·kotlin
雨白6 小时前
协程进阶:协作、互斥与共享状态管理
android·kotlin
studyForMokey1 天前
【Kotlin内联函数】
android·开发语言·kotlin
Larry_zhang双栖1 天前
Flutter Android Kotlin 插件编译错误完整解决方案
android·flutter·kotlin
wuwu_q1 天前
彻底讲清楚 Kotlin 的 when 表达式
android·开发语言·kotlin
QING6181 天前
Jetpack Compose 条件布局与 Layout 内在测量详解
android·kotlin·android jetpack
Kapaseker1 天前
在 Compose 中使用 SurfaceView
android·kotlin