Java Utililty Methods Path File Write nio

List of utility methods to do Path File Write nio

Description

The list of methods to do Path File Write nio are organized into topic(s).

Method

voidwriteStringAndNewLineToBufferedWriter(String line, BufferedWriter writer, Path path)
write String And New Line To Buffered Writer
try {
    writer.write(line);
    writer.newLine();
} catch (IOException ex) {
    throw new IOException("Can't write to " + path, ex);
voidwriteStringToFile(Path path, String data)
write String To File
try (BufferedWriter writer = Files.newBufferedWriter(path, UTF8_CHARSET, StandardOpenOption.WRITE,
        StandardOpenOption.CREATE)) {
    writer.write(data);
} catch (IOException ex) {
    throw new RuntimeException("Failed to write to file " + path.toAbsolutePath().toString(), ex);
voidwriteTagset(Path outPath, Set tagset)
write Tagset
try {
    Files.write(outPath, tagset);
} catch (IOException e) {
    throw new UncheckedIOException(e);
voidwriteTestData(final String testdata, final Path tempfile)
write Test Data
try (final Writer os = Files.newBufferedWriter(tempfile)) {
    os.write(testdata);
voidwriteToFile(double[] testSample, Path classificationTestFile)
write To File
try (BufferedWriter bw = Files.newBufferedWriter(classificationTestFile, StandardCharsets.UTF_8,
        StandardOpenOption.APPEND)) {
    bw.append(Arrays.toString(testSample).replace('[', ' ').replace(']', ' '));
    bw.append('\n');
voidwriteToFile(final Path file, final String text)
write To File
Files.write(file, asList(text), Charset.forName("UTF-8"));
voidwriteToFile(Path file, boolean isAppendingToFile, List lines)
write To File
try {
    if (isAppendingToFile) {
        Files.write(file, lines, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
    } else {
        Files.write(file, Arrays.asList(CSV_HEADER), StandardCharsets.UTF_8);
        Files.write(file, lines, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
} catch (Exception e) {
...
voidwriteToFile(Path path, String string)
Writes the string to a file at the given path, overwriting any file present.
Files.write(path, Collections.singletonList(string), UTF8);
voidwriteToFile(String log, Path path)
write To File
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(path.toFile()))) {
    bufferedWriter.write(log);
} catch (IOException e) {
    e.printStackTrace();
voidwriteToFile(String s, Path file)
write To File
BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8);
writer.append(s);
writer.close();