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

相关推荐
Kapaseker20 小时前
学不动了,入门 Compose Styles API
android·kotlin
plainGeekDev2 天前
MVC 写法 → MVVM
android·java·kotlin
plainGeekDev3 天前
单例模式 → object 声明
android·java·kotlin
rocpp4 天前
Android 多语言切换实战:从 Context 到 Android 13 应用语言适配
android·kotlin
黄林晴4 天前
用了这么久 Koin Scope,原来一直都用错了?
android·kotlin
唐青枫5 天前
Kotlin Context Parameters 详解:别再把 Logger、事务和配置层层往下传
kotlin
Coffeeee5 天前
如何使用Glide和Coil加载WebP动图
android·kotlin·glide
Kapaseker5 天前
5 分钟搞懂 Kotlin DSL
android·kotlin
alexhilton6 天前
使用Android Archive进行打包
android·kotlin·android jetpack
逐光老顽童8 天前
Java 与 Kotlin 混合开发避坑指南:30 个真实案例实录
android·kotlin