我正在尝试在 Android JUNIT 测试用例设置中创建一个文件:
protected void setUp() throws Exception {
super.setUp();
File storageDirectory = new File("testDir");
storageDirectory.mkdir();
File storageFile = new File(storageDirectory.getAbsolutePath()
+ "/test.log");
if (!storageFile.exists()) {
storageFile.createNewFile();
}
mContext = new InternalStorageMockContext(storageFile);
mContextWrapper = new ContextWrapper(mContext);
}
当我调用 createNewFile 时,我得到一个异常没有这样的文件或目录。是否有从 Android JUNIT 创建文件的标准方法?