简体   繁体   English

尝试写入文件,获取FileNotFoundException(只读文件系统)

[英]Trying to write to a file, getting FileNotFoundException (Read-only file system)

So basically I have a program that utilizes Robotium to run tests on an android device, and all the tests work great. 因此,基本上,我有一个利用Robotium在Android设备上运行测试的程序,并且所有测试都能很好地工作。 Certain tests also have timestamps, and I want to save those timestamps to a file so I can use them elsewhere, so I wrote a simple method. 某些测试也带有时间戳,我想将这些时间戳保存到文件中,以便可以在其他地方使用它们,因此我编写了一个简单的方法。

public static void saveTimestamps(Timestamp ts) throws IOException {
    FileWriter fw = new FileWriter(
        "C:\\Users\\brendonn\\workspace\\TestProject\\timestamps.txt");
    fw.write(ts.toString());
    fw.close();
}

But for every test that uses this method I get 但是对于使用此方法的每个测试,我都会得到

java.io.FileNotFoundException: /timestamps.txt (Read-only file system) java.io.FileNotFoundException:/timestamps.txt(只读文件系统)

And I'm not sure where to go from here. 而且我不确定从这里去哪里。 I'm not trying to write to the phone, I'm just writing a text file to my computer. 我不是要写电话,而是要向计算机写一个文本文件。 I can do the exact same thing in other classes on this computer and it works. 我可以在这台计算机上的其他班级做同样的事情,并且可以正常工作。

As near as I can see from a quick look at the Robotium home page, this tool runs ON the target system! 从快速浏览Robotium主页可以看到,该工具可以在目标系统上运行! If that's correct, your method is trying to write to something on the Android device, where the path doesn't exist. 如果正确,则您的方法尝试在路径不存在的Android设备上写入内容。

Note that the front page of the Robotium project talks about a future feature of running the tests from the PC. 请注意,Robotium项目的首页讨论了将来从PC运行测试的功能。

You could try saving the timings to a file on the target device (the app would need permission to write somewhere), or you could perhaps send the data out as log messages and capture the log output on your PC. 您可以尝试将计时保存到目标设备上的文件中(该应用可能需要在其中写入的权限),或者您可以将数据作为日志消息发送出去并捕获PC上的日志输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.FileNotFoundException: (只读文件系统) Mac - java.io.FileNotFoundException: (Read-only file system) Mac Android文件系统:java.io.FileNotFoundException:/ savedArticlesFile:打开失败:EROFS(只读文件系统) - Android file system: java.io.FileNotFoundException: /savedArticlesFile: open failed: EROFS (Read-only file system) java.io.FileNotFoundException:打开失败:EROFS(只读文件系统) - java.io.FileNotFoundException: open failed: EROFS (Read-only file system) java.io.FileNotFoundException:stack.txt:打开失败:EROFS(只读文件系统) - java.io.FileNotFoundException: stack.txt: open failed: EROFS (Read-only file system) Android Studio中的只读文件系统 - Read-only file system in android studio 尝试使用扫描仪读取a.txt文件,但继续获取FileNotFoundException - Trying to read in a.txt file with a scanner but keep getting FileNotFoundException 尝试从资源目录读取Excel文件时获取FileNotFoundException - getting FileNotFoundException when trying to read an excel file from resource directory 尝试读取文件时获取java.io.FileNotFoundException - Getting java.io.FileNotFoundException when trying to read a file Android打开失败:EROFS(只读文件系统)错误 - Android open failed: EROFS (Read-only file system) error java.io.IOException:只读文件系统 - java.io.IOException: Read-only file system
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM