Android 在安卓系统的内部存储器中存储一个大的csv(27MB)
我需要在android的内部存储中存储一个大的csv(27MB)(使用kotlin)。必须存储所有csv数据。 storagehave之后,我需要列出活动中的所有数据(例如在recyclerView中) 做这个最好的方法是什么 如果您想要一个SQL数据库,那么最好使用它 使用Android 11,您将被迫使用作用域存储。那时,旧的请求权限的方式将不起作用 你可以用这样的东西。用户将能够通过standart file App亲自查看文件Android 在安卓系统的内部存储器中存储一个大的csv(27MB),android,kotlin,storage,Android,Kotlin,Storage,我需要在android的内部存储中存储一个大的csv(27MB)(使用kotlin)。必须存储所有csv数据。 storagehave之后,我需要列出活动中的所有数据(例如在recyclerView中) 做这个最好的方法是什么 如果您想要一个SQL数据库,那么最好使用它 使用Android 11,您将被迫使用作用域存储。那时,旧的请求权限的方式将不起作用 你可以用这样的东西。用户将能够通过standart file App亲自查看文件 //opens the File App that is
//opens the File App that is already installed on every Android Device
//it will always save the file in the download folder
//use this start the activity for the File App
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "text/plain"
//user can change the name how he likes later on
//this is just a suggestion for the name
intent.putExtra(Intent.EXTRA_TITLE, "myCSVFile.csv")
startActivityForResult(intent, 1)
当用户在文件应用程序中单击“确定”时
override fun onActivityResult(request:Int, result:Int, resultData: Intent?){
if(resultData != null && resultData.data != null){
//this is the URI for the file that the File App has created
val fUri = resultData.data!!
//get the file descriptor
val pfd: ParcelFileDescriptor = applicationContext.contentResolver.openFileDescriptor(fUri, "w")!!
//create write stream
val bW = FileOutputStream(pfd.fileDescriptor)
//first line of csv file
bW.write(csvHeader.toByteArray())
//best if these 2 lines are in a loop
//the string should not be bigger then 100bytes,
//I have run into exceptions where it said the parcel size was to big
bW.write("\n something something something".toByteArray())
bW.flush()
bW.close()
}
}如果不知道您打算用它做什么,我们就不知道如何存储它。你是在读它,还是在重复?您正在搜索特定的行吗?还有别的吗?第一种是将其保存为文件,第二种是数据库。您需要提供更多的上下文。在内部存储中?在数据库中?一行接一行?我更新了问题。我希望我有更多的启发。