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

相关推荐
AntDreamer3 小时前
在实际开发中,如何根据项目需求调整 RecyclerView 的缓存策略?
android·java·缓存·面试·性能优化·kotlin
极客先躯20 小时前
java和kotlin 可以同时运行吗
android·java·开发语言·kotlin·同时运行
滴水成冰-2 天前
Kotlin-Flow学习笔记
笔记·学习·kotlin
_Shirley3 天前
android.view.InflateException: Binary XML file line #7: Error inflating class
android·xml·java·ide·kotlin·android studio
ChinaDragonDreamer3 天前
Kotlin:1.9.0 的新特性
android·开发语言·kotlin
帅次5 天前
Android Studio:驱动高效开发的全方位智能平台
android·ide·flutter·kotlin·gradle·android studio·android jetpack
深海呐5 天前
Android 用线程池实现一个简单的任务队列(Kotlin)
android·kotlin·线程池·延时任务队列·线程池延时任务
我命由我123456 天前
Kotlin 极简小抄 P2(插值表达式、运算符、选择结构赋值)
android·java·开发语言·后端·kotlin·安卓
宝杰X76 天前
Compose Multiplatform+kotlin Multiplatfrom第三弹
android·开发语言·kotlin
jiet_h7 天前
Kotlin 中的 `flatMap` 方法详解
开发语言·微信·kotlin