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

相关推荐
A0微声z6 小时前
Kotlin Multiplatform (KMP) 中使用 Protobuf
kotlin
alexhilton20 小时前
使用FunctionGemma进行设备端函数调用
android·kotlin·android jetpack
lhDream1 天前
Kotlin 开发者必看!JetBrains 开源 LLM 框架 Koog 快速上手指南(含示例)
kotlin
RdoZam1 天前
Android-封装基类Activity\Fragment,从0到1记录
android·kotlin
Kapaseker1 天前
研究表明,开发者对Kotlin集合的了解不到 20%
android·kotlin
糖猫猫cc2 天前
Kite:两种方式实现动态表名
java·kotlin·orm·kite
如此风景2 天前
kotlin协程学习小计
android·kotlin
Kapaseker2 天前
你搞得懂这 15 个 Android 架构问题吗
android·kotlin
zh_xuan2 天前
kotlin 高阶函数用法
开发语言·kotlin
colicode2 天前
安卓Android语音验证码接口API示例代码:Kotlin/Java版App验证开发
android·java·前端·前端框架·kotlin·语音识别