List of utility methods to do Path File Content
void | writeFile(Path path, String contents) write File try (PrintWriter pw = new PrintWriter(new FileWriter(path.toString(), Boolean.FALSE))) { pw.write(contents); } catch (IOException ex) { ex.printStackTrace(System.err); |
void | writeFile(String path, String content) write File FileOutputStream stream = new FileOutputStream(new File(path)); try { FileChannel fc = stream.getChannel(); stream.write(content.getBytes()); } finally { stream.close(); |
void | writeFile(String path, String content) write File try { Files.write(Paths.get(path), content.getBytes()); } catch (IOException e) { throwRuntime(e); |
void | writeFile(String path, String contents) write File Path p = FileSystems.getDefault().getPath(path); writeFile(p, contents); |
void | writeFileContents(Path to, byte[] contents) write File Contents Files.write(to, contents); |
void | writeJsonToFile(Path jsonPath, String jsonContent) write Json To File BufferedWriter jsonWriter = null; try { jsonWriter = Files.newBufferedWriter(jsonPath, Charset.forName("utf-8")); jsonWriter.write(jsonContent, 0, jsonContent.length()); jsonWriter.flush(); } catch (IOException e) { e.printStackTrace(); } finally { ... |
Path | writeLines(Path base, String file, String[] content) write Lines Path out = base.resolve(file); try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(out, CHARSET))) { for (String line : content) { writer.println(line); } catch (IOException e) { e.printStackTrace(); return out; |
Path | writeString(String content, Path path) write String try { Files.write(path, content.getBytes()); return path; } catch (IOException e) { throw new RuntimeException(e); |
Path | writeStringToFile(String content, Path targetPath) write String To File return Files.write(targetPath, content.getBytes(), StandardOpenOption.CREATE_NEW);
|
void | writeToBinaryFile(String filePath, byte[] binaryContent) write To Binary File Path path = Paths.get(filePath); Files.write(path, binaryContent); |