Hello im following this tutorial, but i dont know much of Kotlin, aknay.github.io can you help me making a translation to java thanks, Also i like to know if the type to csv-xlsx archives is (text/*).
package aknay.readcsv
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.TextView
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
class MainActivity : AppCompatActivity() {
private lateinit var mTextViewCsvResult: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mTextViewCsvResult = findViewById(R.id.textView_csvResult)
findViewById<Button>(R.id.button_loadCsv)?.setOnClickListener {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "text/*"
startActivityForResult(intent, READ_REQUEST_CODE)
}`enter code here`
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
resultData?.let { intent ->
mTextViewCsvResult.text = readCSV(intent.data).joinToString(separator = "
")
}
}
}
@Throws(IOException::class)
fun readCSV(uri: Uri): List<String> {
val csvFile = contentResolver.openInputStream(uri)
val isr = InputStreamReader(csvFile)
return BufferedReader(isr).readLines()
}
companion object {
const val READ_REQUEST_CODE = 123
}
}
question from:
https://stackoverflow.com/questions/66057482/import-and-read-csv-data-in-android 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…