Here you can find the source of writeFile(String fileName, String output)
Parameter | Description |
---|---|
fileName | a parameter |
output | a parameter |
Parameter | Description |
---|
public static void writeFile(String fileName, String output) throws FileNotFoundException, IOException
//package com.java2s; /*/*from www. j av a 2s .c o m*/ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.*; public class Main { /** * Write a String to a file * @param fileName * @param output * @throws java.io.IOException */ public static void writeFile(String fileName, String output) throws FileNotFoundException, IOException { File file = openFile(fileName); if (file == null) { throw new FileNotFoundException(fileName); } Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8")); try { out.write(output); out.flush(); } finally { out.close(); } } /** * Return an instance of File... * * @param path * @return File */ public static File openFile(String path) { try { return new File(path); } catch (Error e) // J#.NET throws an error if the file is not found... { return null; } } public static File openFile(String path, boolean mkdir) { File f = new File(path).getAbsoluteFile(); if (mkdir) { new File(f.getParent()).mkdirs(); } return f; } /** * Return an instance of File... * * @param parentPath * @param fileName * @return File */ public static File openFile(File parentPath, String fileName) { try { return new File(parentPath, fileName); } catch (Error e) // J#.NET throws an error if the file is not found... { return null; } } }