Код: Выделить всё
[/code]
И вот как я читаю текстовые файлы:
Код: Выделить всё
val docFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
val exportsFold = File(docFolder, "ToeApp Exported Reports")
fun makeExportsFolder(){
if (!exportsFold.exists()){
exportsFold.mkdirs()
}
if (!toeAppDir.exists()){
val makecheck = toeAppDir.mkdirs()
Log.i("create File", "MakeCheck: $makecheck")
}
}
fun getExpRep(uri: Uri, context: Context): ExportedRep?{
val docFile = fromSingleUri(context, uri)
val name = docFile?.name
val path = uri.path?.split("/")
Log.i("Path last seg" , "${path?.last()}")
Log.i("file name" , "${name}")
Log.i("Path check", exportsFold.path)
if (name.isNotNull()){
try {
val filePath = File(exportsFold , name)
Log.i("path check" , "Filepath: $filePath")
val content = ByteArray(filePath.length().toInt())
val stream = FileInputStream(filePath)
stream.read(content)
val repJSON = content.decodeToString()
val expRep = Gson().fromJson(repJSON, ExportedRep::class.java)
return expRep
}
catch(e: Exception){
e.printStackTrace()
Toast.makeText(context, "Select Exported Report", Toast.LENGTH_SHORT).show()
return null
}
}
else return null
Код: Выделить всё
java.io.FileNotFoundException: /storage/emulated/0/Documents/ToeApp Exported Reports/Exported_Bruce Wayne_27_06_2024.txt: open failed: EACCES (Permission denied)
Подробнее здесь: https://stackoverflow.com/questions/789 ... files-in-s