Java File Write fileWrite(String filePath, String fileName, String content)

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

Description

file Write

License

Open Source License

Declaration

public static void fileWrite(String filePath, String fileName, String content) throws Exception 

Method Source Code


//package com.java2s;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;

import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static void fileWrite(String filePath, String fileName, String content) throws Exception {
        if (filePath.endsWith("/")) {
            filePath = filePath.substring(0, filePath.length() - 1);
        }/*from  w  w w  .  j a  v  a  2  s  .c  om*/
        File dest = new File(filePath);
        if (!dest.exists()) {
            dest.mkdirs();
        }
        try {
            File file = new File(filePath + "/" + fileName);
            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
            if (content != null) {
                writer.write(content);
            }
            writer.flush();
            writer.close();
        } catch (FileNotFoundException e) {
            throw new Exception(e);
        } catch (IOException e) {
            throw new Exception(e);
        }
    }
}

Related

  1. fileWrite(String filename, byte[] ba)
  2. fileWrite(String fileName, String str)
  3. fileWrite(String filePath, String data)
  4. fileWrite(String path, int format, String content, Object bytesObj)
  5. fileWrite(String[] text, File file)
  6. fileWriteOut(InputStream in, String outPath)
  7. fileWriter(int startpt, int letter)