Lists the children of the given file in a safe way (File#listFiles() can return null).
(File d)
| 74 | /////////////////////////////////////////////////////////////////// |
| 75 | /** Lists the children of the given file in a safe way ({@link File#listFiles()} can return null). */ |
| 76 | public static List<File> list(File d) { |
| 77 | return retry(d, dir -> { |
| 78 | File[] children = dir.listFiles(); |
| 79 | if (children == null) { |
| 80 | if (dir.isFile()) { |
| 81 | throw new IllegalArgumentException("Can't list " + dir + " because it is a file, not a directory."); |
| 82 | } else if (!dir.exists()) { |
| 83 | throw new IllegalArgumentException("Can't list " + dir + " because it does not exist."); |
| 84 | } else { |
| 85 | throw new IllegalArgumentException("Can't list " + dir + ", not sure why."); |
| 86 | } |
| 87 | } else { |
| 88 | return Arrays.asList(children); |
| 89 | } |
| 90 | }); |
| 91 | } |
| 92 | |
| 93 | /** Calls {@link File#mkdirs()} and throws an exception if it fails. */ |
| 94 | public static void mkdirs(File d) { |