Java UTF8 createFileAndExport(String inputFileName, String outputFileName, String outputStr)

Here you can find the source of createFileAndExport(String inputFileName, String outputFileName, String outputStr)

Description

create File And Export

License

Apache License

Declaration

public static void createFileAndExport(String inputFileName, String outputFileName, String outputStr) 

Method Source Code

//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();
        }
    }
}

Related

  1. codesToString(int[] utf8Codes)
  2. codeToString(int utf8Code)
  3. compareWithGold(String goldfile, String outputfile)
  4. convertISO8859_1_to_UTF_8(String s)
  5. ConvertUTF8(byte[] buffer)
  6. createFromUTF8String(DatagramPacket packet, String str)
  7. createTemporaryOutputFolder()
  8. decodePayloadFromUtf8(String utf8string)
  9. decodeUTF8(byte[] bytes)