Android File Create createFile(String file, String content, String encodType)

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

Description

create File

Declaration

public static void createFile(String file, String content,
            String encodType) throws IOException 

Method Source Code

//package com.java2s;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {
    private String message;

    public void createFile(String filePathAndName, String fileContent) {

        try {/*from w  w w . ja va2s . c  o  m*/
            String filePath = filePathAndName;
            filePath = filePath.toString();
            File myFilePath = new File(filePath);
            if (!myFilePath.exists()) {
                myFilePath.createNewFile();
            }
            // FileWriter resultFile = new FileWriter(myFilePath);
            // PrintWriter myFile = new PrintWriter(resultFile);
            // String strContent = fileContent;
            // myFile.println(strContent);
            // myFile.close();
            // resultFile.close();
        } catch (Exception e) {
            message = "?????????";
            e.printStackTrace();
        }
    }

    public static void createFile(String file, String content,
            String encodType) throws IOException {
        FileOutputStream writerStream = new FileOutputStream(file);
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
                writerStream, encodType));
        writer.write(content);
        writer.close();
        writerStream.close();
    }
}

Related

  1. createChecksum(String path)
  2. createFile(File file, boolean isFile)
  3. createFile(String fileName)
  4. createFile(String fileName)
  5. createFile(String filePathAndName, String fileContent)
  6. createFile(String path)