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

相关推荐
无巧不成书02188 小时前
Kotlin Multiplatform (KMP) 鸿蒙开发整合实战|2026最新方案
android·开发语言·kotlin·harmonyos·kmp
无巧不成书02181 天前
Kotlin Multiplatform(KMP)核心解析
android·开发语言·kotlin·交互·harmonyos
我命由我123453 天前
Kotlin 面向对象 - 匿名内部类、匿名内部类简化
android·java·开发语言·java-ee·kotlin·android studio·android jetpack
悠哉清闲4 天前
Future
java·开发语言·kotlin
hewence14 天前
Kotlin CoroutineScope解密
android·开发语言·kotlin
hewence14 天前
重构千行Callback:Android异步回调无损迁移协程Suspend完全指南
android·重构·kotlin
我命由我123454 天前
Android多进程开发 - AIDL 参数方向、AIDL 传递自定义对象、AIDL 传递自定义对象(参数方向)
android·java·java-ee·kotlin·android studio·android jetpack·android-studio
alexhilton5 天前
使用LoRA微调Gemma实现移动端推理
android·kotlin·android jetpack
hewence15 天前
Kotlin协程启动方式详解
android·开发语言·kotlin
RdoZam5 天前
Android-封装个好用、轻量和通用的原生Adapter基类
android·kotlin