List of utility methods to do Path File Name nio
List | subDirectoryNames(final Path dir) Gets the list of subdirectory names in the given directory path. List<String> subdirs = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, Files::isDirectory)) { for (Path subDir : stream) { String conf = subDir.getFileName().toString(); subdirs.add(conf); return subdirs; |
String | toClassName(String path) to Class Name StringBuilder sb = new StringBuilder(); sb.append(normalize(path).replace('-', '_').replace('.', '_').replace('/', '.')); return sb.toString(); |
String | toResourcePath(String fileName) to Resource Path return Paths.get("src", "main", "resources", fileName).toString(); |
void | unzipFile(String fileName, String targetPath) Unzips a zip. final File targetDir = new File(targetPath); final ZipFile sourceZip = new ZipFile(fileName); @SuppressWarnings("unchecked") final Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) sourceZip.entries(); while (entries.hasMoreElements()) { ZipEntry currentEntry = entries.nextElement(); File targetFile = new File(targetDir, currentEntry.getName()); targetFile.getParentFile().mkdirs(); ... |
String | uploadFileToServer(InputStream input, String filename, String usercode, String basePath) upload File To Server Path cloudPath = Paths.get(URI.create(basePath + usercode + "/" + filename)); Files.copy(input, cloudPath, StandardCopyOption.REPLACE_EXISTING); return ALIYUN_URL + cloudPath.toUri().toString(); |
boolean | validateDockerfilePath(String name) validate Dockerfile Path return Files.exists(Paths.get(name)) && Files.isRegularFile(Paths.get(name))
&& Files.isReadable(Paths.get(name));
|
Path | which(Path path, String name) which if (isWindows()) { return path.resolve(name + ".bat"); } else { return path.resolve(name); |
void | writeDataFile(final String resourceName, final Path sourcePath) write Data File copy(Paths.get(currentThread().getContextClassLoader().getResource(resourceName).toURI()),
new FileOutputStream(sourcePath.toFile(), false));
|
void | writeFile(String pathname, String data) Writes a string to the specified file using the default encoding. write(new File(pathname), data, false);
|
int | writeFileFromInputStream(String the_path, String the_filename, InputStream the_sis) Read raw bytes of a text stream and write the data to file specified by the filename. int byteswritten = 0; byte data[] = new byte[BUFFER]; int count = 0; Path destpath = Paths.get(the_path + the_filename); try (OutputStream fos = Files.newOutputStream(destpath, StandardOpenOption.CREATE); BufferedInputStream bis = new BufferedInputStream(the_sis, BUFFER)) { data = new byte[BUFFER]; count = 0; ... |