Android Automator:是否可以在下载文件夹中附加文件?
我已阅读 Kotlin 附加到文件 线程,我的 UIAutomator 代码如下所示:
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")
但从 adb 收到错误日志猫
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论