Reading CSV File In Android App

前端 未结 6 1553
北恋
北恋 2020-12-08 16:14

I\'m working on a proof-of-concept app so that I can implement the feature in a larger app I\'m making. I\'m a bit new to Java and Android Dev but hopefully this shouldn\'t

6条回答
  •  無奈伤痛
    2020-12-08 16:57

    This worked for me in Kotlin. You will need to place the myfile.csv file in the res/raw folder, creating the folder if it isn't there.

    val inputStream: InputStream = resources.openRawResource(R.raw.myfile)
    val reader = BufferedReader(InputStreamReader(inputStream, Charset.forName("UTF-8")))
    reader.readLines().forEach {
    
        //get a string array of all items in this line
        val items = it.split(",")
    
        //do what you want with each item
    }
    

提交回复
热议问题