Here you can find the source of createFile(String file, String content, String encodType)
public static void createFile(String file, String content, String encodType) throws IOException
//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(); } }