List of utility methods to do Path File Write nio
void | writeFully(Path filePath, byte[] bytes) write Fully writeFully(new FileOutputStream(filePath.toFile()), bytes);
|
String | writeJaasConfig(File krbDir, String princ, String keytabPath) write Jaas Config File file = File.createTempFile("jaas_", ".conf", krbDir); file.deleteOnExit(); String jaasData; jaasData = "Client {\n"; jaasData += "com.sun.security.auth.module.Krb5LoginModule required\n"; jaasData += "principal=\"" + princ + "\"\n"; jaasData += "useKeyTab=true\n"; jaasData += "keyTab=\"" + keytabPath + "\"\n"; ... |
void | writeJson(Object data, Path path) Writes the data as a JSON file at the given path if (data == null || path == null) { return; ObjectMapper jsonMapper = new ObjectMapper(); jsonMapper.writeValue(path.toFile(), data); |
void | writeLastReadDate(String sinceDate, Path sinceFile) Simple helper to write the given String into a file ArrayList<String> lines = new ArrayList<String>(); lines.add(sinceDate); Files.write(sinceFile, lines, Charset.forName("UTF-8")); |
void | writeLines(Path path, T... a) write Lines Files.write(path, Arrays.asList(a), StandardCharsets.UTF_8); |
void | writeLineS(String filePath, String msg, int line) Write data to a specific line of a text file. File f = new File(filePath);
List<String> lines = Files.readAllLines(f.toPath());
lines.set(line - 1, msg);
Files.write(f.toPath(), lines);
|
void | writeOrAppendLinesToFile(boolean append, Path filePath, String... lines) write Or Append Lines To File File file = filePath.toFile(); if (!file.exists() && !file.createNewFile()) { return; PrintWriter printWriter = new PrintWriter(Files.newBufferedWriter(file.toPath(), UTF_8, append ? new StandardOpenOption[] { CREATE, APPEND } : new StandardOpenOption[] { CREATE })); for (String line : lines) { printWriter.println(line); ... |
void | writeOutputToFile(Path path) write Output To File BufferedWriter bw = Files.newBufferedWriter(path, Charset.forName("UTF-8"), new OpenOption[] { StandardOpenOption.CREATE }); bw.append(consoleOutputCache.toString()); bw.close(); |
void | writeString(Path path, String str) write String byte[] bytes = str.getBytes("utf-8"); Files.write(path, bytes, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); |
void | writeString(String path, String data) write String try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(path), StandardCharsets.UTF_8))) { writer.write(data); |