문제

If file.delete() is better, how is it? What are the problems of using ProcessBuilder? Also I have to loop through a list to delete the different files. In such a scenario, what is the best approach?

도움이 되었습니까?

해결책

Using java File.delete is better approach, since:

i) Java code will be portable across different OS, if used File.delete() instead of executing OS dependent commands on ProcessBuilder Api. ii) A java programmer can easily understand the functionality written to delete list of different files.

Cons:

i) Since java doesn't allow delete a non-empty directory, we need to write a util method to recursively delete files in directory as shown here, unlike using ProcessBuilder Api, which removes the directory with single command rm -rf

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top