|
@@ -4,11 +4,11 @@ import android.content.ContentUris
|
|
import android.content.Context
|
|
import android.content.Context
|
|
import android.database.Cursor
|
|
import android.database.Cursor
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
-import android.os.Build
|
|
|
|
import android.os.Environment
|
|
import android.os.Environment
|
|
import android.provider.DocumentsContract
|
|
import android.provider.DocumentsContract
|
|
import android.provider.MediaStore
|
|
import android.provider.MediaStore
|
|
import java.io.*
|
|
import java.io.*
|
|
|
|
+import java.nio.charset.Charset
|
|
|
|
|
|
|
|
|
|
object FileKit {
|
|
object FileKit {
|
|
@@ -54,6 +54,29 @@ object FileKit {
|
|
return sb.toString()
|
|
return sb.toString()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fun readFileToStringB(file: File): String {
|
|
|
|
+ val sb = StringBuilder()
|
|
|
|
+ try {
|
|
|
|
+ //打开文件输入流
|
|
|
|
+ val inputStream = FileInputStream(file)
|
|
|
|
+ val inputStreamReader = InputStreamReader(inputStream,Charset.forName("utf-8"))
|
|
|
|
+ val bufferedReader = BufferedReader(inputStreamReader)
|
|
|
|
+ var str: String
|
|
|
|
+ while (bufferedReader.readLine().also { str = it } != null) {
|
|
|
|
+ println("====>字符流:$str")
|
|
|
|
+ sb.append(str)
|
|
|
|
+ }
|
|
|
|
+ bufferedReader.close()
|
|
|
|
+ //关闭输入流
|
|
|
|
+ inputStreamReader.close()
|
|
|
|
+ inputStream.close()
|
|
|
|
+ } catch (ex: Exception) {
|
|
|
|
+ ex.printStackTrace()
|
|
|
|
+ }
|
|
|
|
+ return sb.toString()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
fun writeToFile(file: File, content: String) {
|
|
fun writeToFile(file: File, content: String) {
|
|
try {
|
|
try {
|
|
val out = BufferedWriter(FileWriter(file))
|
|
val out = BufferedWriter(FileWriter(file))
|