ı want to delete my data test history in the allure testng but not in the terminal, ı want to use some functions or any annotation in my java code
Asked
Active
Viewed 418 times
0
-
Search "delete folder in java" in stackoverflow. I found one https://stackoverflow.com/a/23678498/7574461 – lucas-nguyen-17 Dec 15 '21 at 12:06
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 29 '21 at 08:13
1 Answers
0
Try this:
public void deleteDirectory(String directoryPath) throws IOException {
Path path = Paths.get(directoryPath);
try (Stream<Path> walk = Files.walk(path)) {
walk
.sorted(Comparator.reverseOrder())
.forEach(this::deleteTargetDirectory);
}
}
private void deleteTargetDirectory(Path path) {
try {
Files.delete(path);
} catch (IOException e) {
System.err.printf("Unable to delete this path : %s%n%s", path, e);
}
}

Villa_7
- 508
- 4
- 14