Android File Create createFile(String path, String content)

Here you can find the source of createFile(String path, String content)

Description

create File

Declaration


public static boolean createFile(String path, String content) 

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;

import java.util.List;

public class Main {

    public static boolean createFile(String path, String content) {

        try {//from   ww w .j  av a  2 s.c o  m

            File arch = null;

            arch = new File(path);

            BufferedWriter wtr = new BufferedWriter(new FileWriter(arch));
            wtr.write(content);
            wtr.flush();
            wtr.close();

            arch.setWritable(true);
            arch.setReadable(true);
            arch.setExecutable(true);

            return true;

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;

    }

    public static void createFile(String path, List<String> content) {

        File arq = null;

        arq = new File(path);

        write(arq, content);

    }

    public static void write(File file, List<String> content) {

        try {

            BufferedWriter wtr = new BufferedWriter(new FileWriter(file));
            for (String c : content) {
                wtr.write(c);
            }

            wtr.flush();
            wtr.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void write(File file, String content) {

        try {

            BufferedWriter wtr = new BufferedWriter(new FileWriter(file));

            wtr.write(content);

            wtr.flush();
            wtr.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. createFile(String fileName)
  2. createFile(String filePathAndName, String fileContent)
  3. createFile(String path)
  4. createFile(String path)
  5. createFile(String path, List content)
  6. createFile(String path, boolean isFile)
  7. createFileInFolder(File folder, String fileName)
  8. createFileInFolder(File folder, String fileName)
  9. createIfNoExist(String path)