Here you can find the source of writeContent(File file, String content)
Parameter | Description |
---|---|
file | a parameter |
content | a parameter |
public static void writeContent(File file, String content)
//package com.java2s; /*//ww w . ja v a 2 s . c o m * Copyright 2011 gitblit.com. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; public class Main { /** * Writes the string content to the file. * * @param file * @param content */ public static void writeContent(File file, String content) { OutputStreamWriter os = null; try { os = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")); BufferedWriter writer = new BufferedWriter(os); writer.append(content); writer.flush(); } catch (Throwable t) { System.err.println("Failed to write content of " + file.getAbsolutePath()); t.printStackTrace(); } finally { if (os != null) { try { os.close(); } catch (IOException ioe) { System.err.println("Failed to close file " + file.getAbsolutePath()); ioe.printStackTrace(); } } } } }