List of utility methods to do Path File Content
String | readContent(Path file) read Content List<String> lines = Files.readAllLines(file, DEFAULT_CHARSET); StringBuilder sb = new StringBuilder(); for (String line : lines) { sb.append(line).append("\n"); return sb.toString(); |
void | saveByteArrayToFile(byte[] content, Path targetPath) save Byte Array To File File file = targetPath.toFile(); if (!file.exists()) { file.createNewFile(); FileOutputStream fop = new FileOutputStream(file); InputStream is = new ByteArrayInputStream(content); byte[] buf = new byte[4096]; int bytesRead; ... |
void | saveFile(String workspacePath, byte[] content) save File createFoldersIfNecessary(workspacePath); Path path = FileSystems.getDefault().getPath(workspacePath); Files.write(path, content); |
String | slurpFileContent(Path path) Read the content for the given path byte[] buf = new byte[(int) Files.size(path)]; try (InputStream in = Files.newInputStream(path)) { in.read(buf); return new String(buf); |
void | write2File(String contents, Path outputPath) write File if (outputPath != null) { try { outputPath.toFile().getParentFile().mkdirs(); Files.write(outputPath, contents.getBytes()); } catch (IOException e) { e.printStackTrace(); |
void | WriteContentsToFile(String planeTextFilePath, byte[] encryptedData) Write Contents To File Files.write(Paths.get(planeTextFilePath), encryptedData); |
void | writeFile(final String content, final String path) write File try { final PrintWriter writer = new PrintWriter(path); writer.print(""); writer.close(); Files.write(Paths.get(path), content.getBytes(), StandardOpenOption.CREATE); } catch (final IOException e) { e.printStackTrace(); |
void | writeFile(Path file, String content) write File try { Files.write(file, content.getBytes(StandardCharsets.UTF_8)); } catch (final IOException e) { throw new AssertionError("Error writing to file " + file); |
void | writeFile(Path filePath, String content) Writes a file with content to specified filePath . PrintWriter writer = null; try { writer = new PrintWriter(filePath.toString(), "UTF-8"); writer.print(content); } finally { if (writer != null) { writer.close(); |
void | writeFile(Path path, String content) write File PrintWriter writer = null; try { writer = new PrintWriter(path.toString(), "UTF-8"); writer.print(content); } finally { if (writer != null) { writer.close(); |