Java Text File Write nio writeFileContents(File file, String content)

Here you can find the source of writeFileContents(File file, String content)

Description

write File Contents

License

Open Source License

Declaration

public static void writeFileContents(File file, String content) throws Exception 

Method Source Code


//package com.java2s;

import java.io.File;
import java.io.IOException;

import java.nio.file.FileSystems;
import java.nio.file.Files;

import java.nio.file.StandardOpenOption;

public class Main {
    public static void writeFileContents(File file, String content) throws Exception {
        writeFileContents(file, content, Boolean.TRUE);
    }// w  ww .ja v a  2s .c o  m

    private static void writeFileContents(File file, String content, boolean newFile) throws Exception {
        if (file != null && content != null) {
            try {
                Files.write(FileSystems.getDefault().getPath(file.getPath()), content.getBytes(),
                        (newFile ? StandardOpenOption.CREATE : StandardOpenOption.TRUNCATE_EXISTING));
                return;
            } catch (IOException ioe) {
                throw ioe;
            }
        }
        throw new Exception("Invalid or incomplete parameters.");
    }
}

Related

  1. writeContent(File file, String content)
  2. writeContent(File file, String content)
  3. writeData(String address, BigInteger toWrite)
  4. writeDataFromList(String address, ArrayList toWrite)
  5. writeFileContent(File file, String content)
  6. writeFileTxt(String fileName, String[] totalFile)
  7. writeHeader(DataOutput data, String header)
  8. writeIfSet(final OutputStream outputStream, final String field, final String value)
  9. writeLine(final CharBuffer line, final CharBuffer output)