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 屏幕适配完全指南
android·kotlin
黄林晴1 天前
Kotlin Toolchain 太牛了!一个提示词就能构建 KMP 双端应用
android·kotlin
黄林晴1 天前
Kotlin 2.5.0-RC 发布!解构声明稳定,但千万别盲目升级
android·kotlin
松仔log2 天前
Kotlin中级——KMP
android·开发语言·kotlin
传奇开心果编程4 天前
【Jetpack Compose娓娓道来】第55课:传感器与设备姿态——把物理世界的数据接进Compose
android·kotlin·移动开发·传感器·jetpack compose·ui框架·声明式ui
传奇开心果编程4 天前
【Jetpack Compose娓娓道来】第52课:蓝牙与位置权限——把“附近”和“在哪”安全地接进Compose
android·kotlin·移动开发·蓝牙·jetpack compose·声明式ui·位置权限
alexhilton4 天前
卡顿定位:从 UI 线程到 RenderThread
android·kotlin·android jetpack
hai_android8 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
传奇开心果编程9 天前
【Jetpack Compose娓娓道来】第44课:持久化——让数据“关掉App也不丢”
android·kotlin·移动开发·数据持久化·jetpack compose·ui框架·声明式ui
OriginCoding10 天前
一个 JDK 跑起六个分布式挑战:Kotlin 版 Gossip Glomers(一)
分布式·kotlin