Here you can find the source of writeFileUTF8(final File file, final String contents)
Parameter | Description |
---|---|
file | the file to write to. |
contents | the contents of the file to write to. |
Parameter | Description |
---|---|
IOException | if there is an issue writing the file. |
NullPointerException | if the file parameter is null. |
public static void writeFileUTF8(final File file, final String contents) throws IOException
//package com.java2s; /*//www . j a v a 2s . c om * ==================== * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of the Common Development * and Distribution License("CDDL") (the "License"). You may not use this file * except in compliance with the License. * * You can obtain a copy of the License at * http://opensource.org/licenses/cddl1.php * See the License for the specific language governing permissions and limitations * under the License. * * When distributing the Covered Code, include this CDDL Header Notice in each file * and include the License file at http://opensource.org/licenses/cddl1.php. * If applicable, add the following below this CDDL Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * ==================== * Portions Copyrighted 2013 ConnId * Portions Copyrighted 2015 ForgeRock AS. */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; public class Main { public static final String UTF8 = "UTF-8"; /** * Write the contents of the string out to a file in UTF-8 format. * * @param file * the file to write to. * @param contents * the contents of the file to write to. * @throws IOException * if there is an issue writing the file. * @throws NullPointerException * if the file parameter is null. */ public static void writeFileUTF8(final File file, final String contents) throws IOException { final Writer writer = new OutputStreamWriter(new FileOutputStream(file), UTF8); try { writer.write(contents); } finally { writer.close(); } } }