List of utility methods to do Path Create nio
void | createFile(Path path) create File File file = path.toFile();
if (file.exists()) {
file.delete();
file.createNewFile();
|
void | createFile(String filePath, String content) create File File file = new File(filePath); try { if (!file.exists()) { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); fos.write(content.getBytes(Charset.forName("UTF-8"))); fos.flush(); fos.close(); } catch (IOException e) { e.printStackTrace(); |
boolean | createFile(String workspacePath) create File createFoldersIfNecessary(workspacePath); File file = new File(workspacePath); if (!file.exists()) { return file.createNewFile(); return true; |
Path | createFileForReport(Path reportDir, String filePrefix, String fileSuffix) create File For Report Path reportFile = reportDir.resolve(filePrefix + "_validation_result." + fileSuffix); for (int i = 1; Files.exists(reportFile); i++) { reportFile = reportDir.resolve(filePrefix + "(" + i + ")_validation_result." + fileSuffix); return reportFile; |
void | createFileFromText(String sourceText, IPath path) Creates a file from input string text. Preconditions.checkArgument(path.isAbsolute()); Path file = FileSystems.getDefault().getPath(path.toOSString()); Files.write(file, sourceText.getBytes()); |
void | createFileIfNotExist(Path path) create File If Not Exist try (FileChannel f = FileChannel.open(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
|
boolean | createFileIfNotExists(Path path) create File If Not Exists if (Files.notExists(path) || !path.toFile().exists()) { Files.createFile(path); return true; return false; |
URI | createFileRelativeToClasspath(String resourceName) create File Relative To Classpath final File file = Paths.get(new File("").getAbsolutePath(), resourceName).toFile(); file.mkdirs(); if (!file.exists()) { file.delete(); file.createNewFile(); return file.toURI(); |
Path | createFileWithContents(String pathString, String contents) create File With Contents Path path = FileSystems.getDefault().getPath(pathString); if (exists(path)) { throw new IOException("File " + pathString + " already exists."); } else { createFile(path); try (BufferedWriter out = newBufferedWriter(path, Charset.defaultCharset())) { out.write(contents); ... |
boolean | createFolder(String workspacePath) create Folder File folder = new File(workspacePath); if (!folder.exists()) { return folder.mkdirs(); return true; |