Java Path File Write nio writeToFile(Path file, boolean isAppendingToFile, List lines)

Here you can find the source of writeToFile(Path file, boolean isAppendingToFile, List lines)

Description

write To File

License

Open Source License

Declaration

static void writeToFile(Path file, boolean isAppendingToFile,
            List<String> lines) 

Method Source Code

//package com.java2s;
/**//from  w w w.  java2 s  . c  o  m
 * Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
 * All rights reserved.
 *
 * This file is licensed under the BSD 2-Clause License, which accompanies this project
 * and is available under https://opensource.org/licenses/BSD-2-Clause.
 */

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import java.util.Arrays;
import java.util.List;

public class Main {
    final static String CSV_HEADER = "elementCount,run,className,dataType,archetype,supportsStagedMutability,footprintInBytes,footprintInObjects,footprintInReferences";

    static void writeToFile(Path file, boolean isAppendingToFile,
            List<String> lines) {
        // write stats 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) {
            e.printStackTrace();
        }
    }
}

Related

  1. writeStringToFile(Path path, String data)
  2. writeTagset(Path outPath, Set tagset)
  3. writeTestData(final String testdata, final Path tempfile)
  4. writeToFile(double[] testSample, Path classificationTestFile)
  5. writeToFile(final Path file, final String text)
  6. writeToFile(Path path, String string)
  7. writeToFile(String log, Path path)
  8. writeToFile(String s, Path file)
  9. writeUntouchedImage(Path sourceFile, Path destFile)