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

相关推荐
androidwork2 小时前
Android LinearLayout、FrameLayout、RelativeLayout、ConstraintLayout大混战
android·java·kotlin·androidx
androidwork4 小时前
OkHttp 3.0源码解析:从设计理念到核心实现
android·java·okhttp·kotlin
莉樱Yurin5 小时前
Kotlin/CLR 让Kotlin走进.NET世界
kotlin
casual_clover5 小时前
Android 之 kotlin 语言学习笔记四(Android KTX)
android·学习·kotlin
移动开发者1号7 小时前
Android 大文件分块上传实战:突破表单数据限制的完整方案
android·java·kotlin
移动开发者1号7 小时前
单线程模型中消息机制解析
android·kotlin
梓仁沐白1 天前
【Kotlin】协程
开发语言·python·kotlin
WAsbry1 天前
现代 Android 开发自定义主题实战指南
android·kotlin·material design
梓仁沐白1 天前
【Kotlin】注解&反射&扩展
开发语言·python·kotlin
移动开发者1号1 天前
Jetpack Compose瀑布流实现方案
android·kotlin