Java Text File Write nio writeAllText(File file, String contents)

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

Description

write All Text

License

Open Source License

Declaration

public static void writeAllText(File file, String contents) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2013, 2014 ETAS GmbH./*  w  w  w  .  j a v  a  2 s. c  o  m*/
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Dennis Eder (ETAS GmbH) - initial API and implementation and/or initial documentation
*******************************************************************************/

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class Main {
    final static Charset ENCODING = StandardCharsets.UTF_8;

    public static void writeAllText(File file, String contents) throws IOException {
        FileOutputStream fos = new FileOutputStream(file);
        OutputStreamWriter out = new OutputStreamWriter(fos, ENCODING);
        out.write(contents);
        out.close();
    }
}

Related

  1. write(OutputStream stream, String string)
  2. write(String content, String file)
  3. write(String location, String content)
  4. write(String msg)
  5. writeAllLines(File file, List list)
  6. writeArray2File(File file, Object[] objects, String code)
  7. writeAscii(CharSequence ascii, OutputStream os)
  8. writeContent(File file, String content)
  9. writeContent(File file, String content)