Java Write String to File writeFile(final File file, final String contents)

Here you can find the source of writeFile(final File file, final String contents)

Description

write File

License

Open Source License

Declaration

protected static void writeFile(final File file, final String contents) throws IOException 

Method Source Code


//package com.java2s;

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

public class Main {
    protected static void writeFile(final File file, final String contents) throws IOException {
        final File dir = file.getParentFile();
        if (dir != null && !dir.isDirectory() && !dir.mkdirs())
            throw new IOException("Could not make " + dir);
        final FileWriter writer = new FileWriter(file);
        writer.write(contents);//from w w  w  .ja va 2s  . c  om
        writer.close();
    }
}

Related

  1. writeFile(File file, String... lines)
  2. writeFile(File file, String... lines)
  3. writeFile(File file, StringBuffer buffer)
  4. writeFile(File filename, ArrayList lines)
  5. writeFile(final File file, final String content)
  6. writeFile(final File file, final String contents)
  7. writeFile(final File iFile, final String iContent)
  8. writeFile(String absoluteFileName, String content, boolean append)
  9. writeFile(String aContent, String aFileName)