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
相关产品推荐
相关产品推荐

