File tree 1 file changed +4
-1
lines changed
libraries-io/src/test/java/com/baeldung/java/io
1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 13
13
import java .util .Arrays ;
14
14
import java .util .Comparator ;
15
15
import java .util .List ;
16
+ import java .util .stream .Stream ;
16
17
17
18
import org .apache .commons .io .FileUtils ;
18
19
import org .junit .After ;
@@ -110,7 +111,9 @@ public void givenDirectory_whenDeletedWithSpringFileSystemUtils_thenIsGone() thr
110
111
public void givenDirectory_whenDeletedWithFilesWalk_thenIsGone () throws IOException {
111
112
Path pathToBeDeleted = TEMP_DIRECTORY .resolve (DIRECTORY_NAME );
112
113
113
- Files .walk (pathToBeDeleted ).sorted (Comparator .reverseOrder ()).map (Path ::toFile ).forEach (File ::delete );
114
+ try (Stream <Path > paths = Files .walk (pathToBeDeleted )) {
115
+ paths .sorted (Comparator .reverseOrder ()).map (Path ::toFile ).forEach (File ::delete );
116
+ }
114
117
115
118
assertFalse ("Directory still exists" , Files .exists (pathToBeDeleted ));
116
119
}
You can’t perform that action at this time.
0 commit comments