Java File Write fileWrite(String fileName, String str)

Here you can find the source of fileWrite(String fileName, String str)

Description

file Write

License

Open Source License

Declaration

public static void fileWrite(String fileName, String str) 

Method Source Code

//package com.java2s;
/*//from   www  . j a  v a2  s. c  o m
****************************************************
* REsolution is an automatic software refactoring tool      
****************************************************
 *  Copyright (c) 2016, Wang Ying, Yin Hongjian, YU Hai, ZHU Zhiliang.
 *  E-mail: yuhai@126.com
 *  All rights reserved.
 *
 * This file is part of REsolution.
 *
 * REsolution is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * REsolution is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with REsolution.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.io.File;
import java.io.FileOutputStream;

import java.io.IOException;

public class Main {
    public static void fileWrite(String fileName, String str) {
        File file = new File(fileName);
        FileOutputStream fopstream = null;
        try {
            fopstream = new FileOutputStream(file);
            fopstream.write(str.getBytes());
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } finally {
            try {
                fopstream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }

    public static void fileWrite(File file, String str) {

        FileOutputStream fopstream = null;
        try {
            fopstream = new FileOutputStream(file);
            fopstream.write(str.getBytes());
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } finally {
            try {
                fopstream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }
}

Related

  1. fileWrite(String filename, byte[] ba)
  2. fileWrite(String filePath, String data)
  3. fileWrite(String filePath, String fileName, String content)
  4. fileWrite(String path, int format, String content, Object bytesObj)
  5. fileWrite(String[] text, File file)