List of utility methods to do Path File Write nio
boolean | robustCheckWriteable(Path logFile) robust Check Writeable try { return Files.isWritable(logFile.getParent()) && (!Files.exists(logFile) || Files.isWritable(logFile)); } catch (Throwable ex) { logGetLogPathError(ex.getMessage()); return false; |
void | save(Object o, String path) save ObjectOutputStream stream = createObjectOutputStreamTo(path); try { stream.writeObject(o); stream.close(); } catch (IOException e) { throw new RuntimeException(e); |
void | saveFile(String path, String text) Writes a text file (as UTF-8). byte[] encoded = text.getBytes(StandardCharsets.UTF_8);
Files.write(Paths.get(path), encoded);
|
void | saveHeaders(Path path, ArrayList save Headers try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { for (String line : headers) { writer.write(line); writer.newLine(); } catch (IOException e) { e.printStackTrace(); |
void | saveProperties(Path filePath, Properties prop) save Properties if (Files.exists(filePath)) Files.delete(filePath); try (Writer w = Files.newBufferedWriter(filePath)) { prop.store(w, ""); |
void | saveTo(String path, InputStream in) Saves content read from input stream into a file. if (in == null) throw new IllegalArgumentException("input stream cannot be null"); if (path == null) throw new IllegalArgumentException("path cannot be null"); try (OutputStream out = new BufferedOutputStream( Files.newOutputStream(Paths.get(path), StandardOpenOption.CREATE, StandardOpenOption.APPEND))) { byte[] bytes = new byte[1024]; for (int x = in.read(bytes); x != -1; x = in.read(bytes)) ... |
void | saveToFile(String path, byte[] text) save To File try { Files.write(Paths.get(path), text); } catch (IOException e) { e.printStackTrace(); |
void | setPosixPermissions(String path, boolean ownerRead, boolean ownerWrite, boolean ownerExecute, boolean groupRead, boolean groupWrite, boolean groupExecute, boolean othersRead, boolean othersWrite, boolean othersExecute) set Posix Permissions 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<?> posixFileAttributeViewClass = Class.forName("java.nio.file.attribute.PosixFileAttributeView"); Class<?> filesClass = Class.forName("java.nio.file.Files"); Class<?> linkOptionClass = Class.forName("java.nio.file.LinkOption"); Class<?> posixFilePermissionClass = Class.forName("java.nio.file.attribute.PosixFilePermission"); Method fileSystemsGetDefaultMethod = fileSystemsClass.getMethod("getDefault"); ... |
Path | srcImageToSavePath(String src, Path saveFolder) src Image To Save Path int indexName = src.lastIndexOf("/"); if (indexName == src.length()) { src = src.substring(1, indexName + 1); indexName = src.lastIndexOf("/") + 1; String name = src.substring(indexName, src.length()); return saveFolder.resolve(name); |
void | write(List Write the list specified to the output path specified try { Files.write(Paths.get(outputPath), list, StandardCharsets.UTF_8); } catch (IOException e) { throw new UncheckedIOException(e); |