1 year ago
#288507
pvd
Android Automator: Is it possible to append file in Download folder?
I've read the Kotlin append to file thread, and my UIAutomator code looks like:
fun appendLog(text: String?) {
val logFile = File("/sdcard/Download/autotest.log")
if (!logFile.exists()) {
try {
logFile.createNewFile()
Log.d(TAG, "Create new file $logFile Succeed!")
} catch (e: IOException) {
Log.e(TAG, "Create new file $logFile FAILED!, $e")
}
}
try {
FileOutputStream(logFile, true).bufferedWriter().use { writer ->
writer.append(text)
writer.newLine()
}
} catch (e: IOException) {
Log.e(TAG, "Appending file $logFile FAILED!, $e")
}
}
// test cas 1
appendLog("Some test result")
// test cas 2
appendLog("Other test results")
But got error from adb logcat
03-14 20:16:57.829 27499 27522 D LogTest : Create new file /sdcard/Download/autotest.log Succeed!
03-14 20:16:57.830 27499 27522 E LogTest : Appending file /sdcard/Download/autotest.log FAILED!, java.io.FileNotFoundException: /sdcard/Download/autotest.log: open failed: EEXIST (File exists)
03-14 20:17:02.214 27499 27522 D LogTest : Create new file /sdcard/Download/autotest.log Succeed!
03-14 20:17:02.216 27499 27522 E LogTest : Appending file /sdcard/Download/autotest.log FAILED!, java.io.FileNotFoundException: /sdcard/Download/autotest.log: open failed: EEXIST (File exists)
android
kotlin
android-file
android-uiautomator
0 Answers
Your Answer