/** * Creates a new file using the given path. * * @param path the path of the new file. * @return the new created file. * @throws RuntimeException if the path belongs to an existing non-empty directory. * @throws RuntimeException if the path belongs to an existing file. * @throws UncheckedIOException if any I/O error is thrown when creating the new file. */ public static File newFile(String path) { File file = createFileIfPathIsNotANonEmptyDirectory(path); try { if (!file.createNewFile()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (IOException e) { throw cannotCreateNewFile(path, e); } return file; }
/** * Creates a new directory using the given path. * * @param path the path of the new directory. * @return the new created directory. * @throws RuntimeException if the path belongs to an existing non-empty directory. * @throws RuntimeException if the path belongs to an existing file. * @throws RuntimeException if any I/O error is thrown when creating the new directory. */ public static File newFolder(String path) { File file = createFileIfPathIsNotANonEmptyDirectory(path); try { if (!file.mkdir()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (Exception e) { throw cannotCreateNewFile(path, e); } return file; }
/** * Creates a new file using the given path. * * @param path the path of the new file. * @return the new created file. * @throws RuntimeException if the path belongs to an existing non-empty directory. * @throws RuntimeException if the path belongs to an existing file. * @throws UncheckedIOException if any I/O error is thrown when creating the new file. */ public static File newFile(String path) { File file = createFileIfPathIsNotANonEmptyDirectory(path); try { if (!file.createNewFile()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (IOException e) { throw cannotCreateNewFile(path, e); } return file; }
/** * Creates a new directory using the given path. * * @param path the path of the new directory. * @return the new created directory. * @throws RuntimeException if the path belongs to an existing non-empty directory. * @throws RuntimeException if the path belongs to an existing file. * @throws RuntimeException if any I/O error is thrown when creating the new directory. */ public static File newFolder(String path) { File file = createFileIfPathIsNotANonEmptyDirectory(path); try { if (!file.mkdir()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (Exception e) { throw cannotCreateNewFile(path, e); } return file; }
/** * Creates a new file using the given path. * * @param path the path of the new file. * @return the new created file. * @throws FilesException if the path belongs to an existing non-empty directory. * @throws FilesException if the path belongs to an existing file. * @throws FilesException if any I/O error is thrown when creating the new file. */ public static File newFile(String path) { File file = createFileIfPathIsNotANonEmptyDirectory(path); try { if (!file.createNewFile()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (IOException e) { throw cannotCreateNewFile(path, e); } return file; }
/** * Creates a new directory using the given path. * * @param path the path of the new directory. * @return the new created directory. * @throws FilesException if the path belongs to an existing non-empty directory. * @throws FilesException if the path belongs to an existing file. * @throws FilesException if any I/O error is thrown when creating the new directory. */ public static File newFolder(String path) { File file = createFileIfPathIsNotANonEmptyDirectory(path); try { if (!file.mkdir()) { throw cannotCreateNewFile(path, "a file was found with the same path"); } } catch (Exception e) { throw cannotCreateNewFile(path, e); } return file; }