как это сделать
File file = new File("xxxx");
file.exists() возвращает true .
Код: Выделить всё
public void testFile(String path) {
File file = new File(path);
if (file.exists()) {
System.out.println("文件存在!");
} else {
System.out.println("文件不存在!");
}
}
Файл fileMock;
when(fileMock.exists()).thenReturn(true);fileMock не имеет связи с локальной переменной file в методе. Итак, как мне заставить file.exists возвращать true без создания файла?
Подробнее здесь: https://stackoverflow.com/questions/786 ... ile-exists