Java Utililty Methods Text File Write nio

List of utility methods to do Text File Write nio

Description

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

Method

voidwriteTextFile(String file, String articleContent)
write Text File
PrintWriter out = new PrintWriter(
        new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")));
out.println(articleContent);
out.close();
if (out.checkError()) {
    throw new IOException("Error saving " + file);
voidwriteTo(File file, String content)
write To
Path path = file.toPath();
writeTo(path, content);
voidwriteToFile(File file, String content)
Writes given string to a file.
createFile(file);
Files.write(file.toPath(), content.getBytes(CHARSET));
voidwriteToFile(File file, String str)
write To File
if (!file.getParentFile().exists()) {
    file.getParentFile().mkdirs();
if (!file.exists()) {
    try {
        file.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
...
voidwriteToFile(final File file, final String data)
Write a UTF-8 string to a file object.
writeToFile(file.toPath(), data);
FilewriteToFile(String content, String fileName)
Creates file under temporary file directory and writes configuration to it.
File temp = null;
BufferedWriter bw = null;
try {
    temp = new File(System.getProperty("java.io.tmpdir") + File.separator + fileName);
    bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(temp), StandardCharsets.UTF_8));
    bw.write(content);
    bw.flush();
} catch (RuntimeException e) {
...
voidwriteToFile(String content, String fileName, boolean createFile)
write To File
writeToFile(content.getBytes(DEFAULT_UTF_8_CHARSET), fileName, createFile);
voidwriteToFile(String filename, String fileContents)
write To File
Writer writer = null;
try {
    writer = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.US_ASCII));
    writer.write(fileContents);
} catch (IOException e) {
    e.printStackTrace();
} finally {
...
booleanwriteToFile(String filename, String... lines)
write To File
Path p = Paths.get(filename);
try (BufferedWriter bw = new BufferedWriter(Files.newBufferedWriter(p))) {
    for (String l : lines) {
        bw.write(l);
        bw.newLine();
} catch (IOException ex) {
    return false;
...
voidwriteTokenText(OutputStream theOs, String theStr)
write Token Text
theOs.write(theStr.getBytes(StandardCharsets.UTF_8));
theOs.write(0x00);