Here you can find the source of writeFile(String filePath, String content)
Parameter | Description |
---|---|
filePath | a parameter |
content | a parameter |
public static void writeFile(String filePath, String content)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006 Bruno G. Braga. 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 * /* w w w . j a va 2 s .c o m*/ * Contributors: Bruno G. Braga - initial API and implementation *******************************************************************************/ import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; public class Main { /** * Write content to file. * @param filePath * @param content */ public static void writeFile(String filePath, String content) { try { // Open or create the output file FileOutputStream os = new FileOutputStream(filePath); FileDescriptor fd = os.getFD(); // Write some data to the stream os.write(content.getBytes()); // Flush the data from the streams and writers into system buffers. // The data may or may not be written to disk. os.flush(); // Block until the system buffers have been written to disk. // After this method returns, the data is guaranteed to have // been written to disk. fd.sync(); } catch (IOException e) { e.printStackTrace(); } } }