Java Text File Save writeFile(String path, String fileName, String data)

Here you can find the source of writeFile(String path, String fileName, String data)

Description

write File

License

Open Source License

Declaration

public static void writeFile(String path, String fileName, String data) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static void writeFile(String path, String fileName, String data) throws IOException {
        createPath(path);// w  ww.  ja va  2s. c  om
        String fullPath = path + fileName;
        File file = new File(fullPath);
        if (!file.exists()) {
            file.createNewFile();
        }
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
        bufferedWriter.write(data);
        bufferedWriter.close();
    }

    private static void createPath(String path) {
        File dir = new File(path);
        if (!(dir.exists())) {
            dir.mkdirs();
        }
    }
}

Related

  1. writefile(String path, String content, boolean append)
  2. writeFile(String path, String contents)
  3. writeFile(String path, String data)
  4. writeFile(String path, String fileName, String content)
  5. writeFile(String path, String fileName, String content, String charset)
  6. writeFile(String path, String text)
  7. writeFile(String path, String text)
  8. writeFile(String path, String text, boolean orverWite)
  9. writeFile(String path, Vector contents)