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

相关推荐
D e re k ZH2 小时前
保序回归:从 PAVA 到可并堆的单调约束优化
c++·算法·数据挖掘·回归·kotlin
Goway_Hui3 小时前
【KMP for OpenHarmony】Cache4k 0.14.0 鸿蒙适配
华为·kotlin·harmonyos
YB13754 小时前
kotlin与函数式编程
kotlin
我是唐青枫16 小时前
Kotlin Delegation 委托详解
开发语言·kotlin
唐青枫1 天前
Kotlin Inheritance(继承)详解:语法、原理、实战 Demo
kotlin
alexhilton2 天前
用Konsist与Lint强制执行设计系统契约
android·kotlin·android jetpack
唐青枫2 天前
Kotlin Delegation 委托详解
kotlin
传奇开心果3 天前
Compose Multiplatform 共享边界实战:架构契约、互操作同步与可回退设计
android·kotlin
腾讯端服务3 天前
一码Duo端-Kuikly-iOS折叠屏新UI适配实践
android·ui·ios·kotlin·鸿蒙
传奇开心果4 天前
【Compose Multiplatform跨端声明式UI实用技术】第19课:多平台部署与发布
android·kotlin