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

相关推荐
儿歌八万首16 小时前
Jetpack Compose 动画实战:让你的 UI 动起来
android·kotlin·动画·compose
stevenzqzq19 小时前
Android Koin 注入入门教程
android·kotlin
zFox19 小时前
三、Kotlin协程+异步加载+Loading状态
kotlin·android jetpack·协程
shuangrenlong20 小时前
笔记kotlin注意的点
kotlin
Android-Flutter1 天前
android compose LazyVerticalGrid上下滚动的网格布局 使用
android·kotlin
Android-Flutter1 天前
android compose LazyHorizontalGrid水平滚动的网格布局 使用
android·kotlin
我命由我123451 天前
Kotlin 面向对象 - 装箱与拆箱
android·java·开发语言·kotlin·android studio·android jetpack·android-studio
我命由我123451 天前
Android Jetpack Compose - Snackbar、Box
android·java·java-ee·kotlin·android studio·android jetpack·android-studio
alexhilton1 天前
Jetpack Compose内部的不同节点类型
android·kotlin·android jetpack
我命由我123452 天前
Kotlin 运算符 - == 运算符与 === 运算符
android·java·开发语言·java-ee·kotlin·android studio·android-studio