You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kotlin数据类读取assets中CSV文件失败求助

问题:读取Assets目录下CSV文件失败

我正在编写一个Bird数据类,想要读取CSV文件获取其中存储的信息,但尝试的所有文件读取方式均无效。

以下是我目前的尝试代码:

data class Bird(val birdNumIn: Int){
    private var birdNum = birdNumIn

    /**
     * A function that searches the bird-data.csv file which is a list of birds to find the bird that was
     * inputted into the class constructor and then add the values of the bird to the private variables.
     */
    fun updateValues(){
        var birdNumber = birdNum
        var birdInfo: MutableList<String> = mutableListOf()

        val minput = InputStreamReader(assets().open("bird-data.csv"), "UTF-8")
        val reader = BufferedReader(minput)
    }
}

使用assets().open("bird-data.csv")方法无法正常工作,返回文件不存在的错误,但该文件确实存在于assets文件夹中,且文件名拼写正确。我还尝试了其他多种文件读取方法,例如使用Java.io.File及文件路径读取,同样无效。

内容的提问来源于stack exchange,提问作者Jackson North

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 22:33:31