List of utility methods to do Path Create nio
List | createRandomFolders(Path basePath, int numberOfFolders) create Random Folders List<Path> folders = new ArrayList<>(); for (int i = 0; i < numberOfFolders; ++i) { Path folder = createRandomFolder(basePath); folders.add(folder); return folders; |
String | createRelativePath(File baseDirFile, File file) create Relative Path if (baseDirFile == null) throw new IllegalArgumentException("baseDirFile must not be null"); if (file == null) throw new IllegalArgumentException("file must not be null"); Path basePath = baseDirFile.toPath().normalize(); Path filePath = file.toPath().normalize(); return basePath.relativize(filePath).toString(); |
SourceFile | createSourceFile(Path path, String... lines) create Source File return SourceFile.fromCode(path.toString(), Joiner.on("\n").join(lines)); |
void | createSymbolicLink(String linkPathString, String targetPathString) create Symbolic Link Class<?> fileSystemsClass = Class.forName("java.nio.file.FileSystems"); Class<?> fileSystemClass = Class.forName("java.nio.file.FileSystem"); Class<?> pathClass = Class.forName("java.nio.file.Path"); Class<?> filesClass = Class.forName("java.nio.file.Files"); Class<?> fileAttributeClass = Class.forName("java.nio.file.attribute.FileAttribute"); Object emptyFileAttributeArray = Array.newInstance(fileAttributeClass, 0); Method fileSystemsGetDefaultMethod = fileSystemsClass.getMethod("getDefault"); Method fileSystemGetPathMethod = fileSystemClass.getMethod("getPath", String.class, String[].class); ... |
void | createSymlink(Path realFileLocation, Path softLinkLocation) create Symlink try { Files.createSymbolicLink(softLinkLocation, realFileLocation); } catch (IOException e) { System.err.println(e); } catch (UnsupportedOperationException e) { System.err.println(e); |
void | createSymlink(String targetPathStr, File symlinkFile) create Symlink Path targetPath = Paths.get(targetPathStr); Path symlinkPath = Paths.get(symlinkFile.getPath()); Files.createSymbolicLink(symlinkPath, targetPath); |
Path | createTempDirectory(final String path, final String prefix) create Temp Directory FileSystem fs = FileSystems.getDefault();
Path temp = Files.createTempDirectory(fs.getPath(path), prefix);
return temp;
|
Path | createTempDirectory(Path dir, String prefix) Create a temporary directory with the same attributes as its parent directory. try { return Files.createTempDirectory(dir, prefix); } catch (UnsupportedOperationException ex) { return Files.createTempDirectory(dir, prefix); |
Path | createTempFile(Path baseDir, String prefix, String suffix) create Temp File Path tmp = Files.createTempFile(baseDir, prefix, suffix);
tmp.toFile().deleteOnExit();
return tmp;
|
Path | createTempFilePath(final String stem, final String extension) create Temp File Path final Path tempFilePath = createTempFile("schemacrawler." + stem + ".", "." + extension).normalize() .toAbsolutePath(); delete(tempFilePath); tempFilePath.toFile().deleteOnExit(); return tempFilePath; |