Java File Write via ByteBuffer writeFileAsStringArray(File file, String[] par2DataArray)

Here you can find the source of writeFileAsStringArray(File file, String[] par2DataArray)

Description

write File As String Array

License

Open Source License

Declaration

public static void writeFileAsStringArray(File file, String[] par2DataArray) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;

public class Main {
    private static Charset _charset = Charset.defaultCharset();

    public static void writeFileAsStringArray(File file, String[] par2DataArray) throws IOException {
        StringBuilder sb = new StringBuilder();
        for (String t : par2DataArray) {
            sb.append(t);/*  w w w. j ava2 s  . c o m*/
        }
        writeFileAsString(file, sb.toString());
    }

    public static void writeFileAsString(File file, String par2Data) throws IOException {
        writeFileAsByteArray(file, par2Data.getBytes(_charset));
    }

    public static void writeFileAsByteArray(File file, byte[] par2Data) throws IOException {
        ByteBuffer bb;
        FileChannel fc = null;
        try {
            fc = new FileOutputStream(file).getChannel();
            bb = ByteBuffer.wrap(par2Data);
            fc.write(bb);
        } finally {
            if (fc != null)
                fc.close();
        }
    }
}

Related

  1. writeFC(String fname, float[] res)
  2. writeFile(File file, byte[] bytes)
  3. writeFile(File file, byte[] data)
  4. writeFile(String source, File outputFile)
  5. writeFileAsByteArray(File file, byte[] par2Data)
  6. writeFileNIO(String txt, File fyl)
  7. writeFloat(OutputStream os, float val, ByteOrder bo)
  8. writeInt(OutputStream os, int val, ByteOrder bo)
  9. writeInt(OutputStream out, ByteOrder order, int i)