Here you can find the source of createFileAndExport(String inputFileName, String outputFileName, String outputStr)
public static void createFileAndExport(String inputFileName, String outputFileName, String outputStr)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.nio.channels.FileChannel; import java.util.List; public class Main { public static void createFileAndExport(String inputFileName, String outputFileName, String outputStr) { FileChannel inputChannel = null; FileChannel outputChannel = null; try {//from w ww . j a va 2s.co m File input = new File(inputFileName); File output = new File(outputFileName); inputChannel = new FileInputStream(input).getChannel(); outputChannel = new FileOutputStream(output).getChannel(); outputChannel.transferFrom(inputChannel, 0, inputChannel.size()); inputChannel.close(); outputChannel.close(); exportToFile(outputFileName, outputStr, false); } catch (IOException e) { e.printStackTrace(); } } public static void exportToFile(String fileName, String output, boolean append) { try { FileWriter writer = new FileWriter(fileName, append); writer.append(output + "\n"); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } public static void exportToFile(List<String> outputList, String fileName) { try { FileWriter writer = new FileWriter(fileName); for (String str : outputList) { writer.append(str + "\n"); } writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }