Java FileOutputStream Write Byte Array writeBytes(File file, byte[] bytes)

Here you can find the source of writeBytes(File file, byte[] bytes)

Description

write Bytes

License

Apache License

Declaration

public static void writeBytes(File file, byte[] bytes) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    private final static String UTF8 = "UTF-8";

    public static void writeBytes(File file, byte[] bytes) throws IOException {
        FileOutputStream out = new FileOutputStream(file);
        out.write(bytes);/*from  w  ww . j ava  2  s. co m*/
        out.close();
    }

    public static void write(File file, String content) throws IOException {
        writeBytes(file, utf8(content));
    }

    public static byte[] utf8(String string) {
        try {
            return string.getBytes(UTF8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String utf8(byte[] bytes) {
        try {
            return new String(bytes, UTF8);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. writeBytes(File file, byte[] arr)
  2. writeBytes(File file, byte[] ba)
  3. writeBytes(File file, byte[] bytes)
  4. writeBytes(File file, byte[] bytes)
  5. writeBytes(File file, byte[] bytes)
  6. writeBytes(File file, byte[] bytes, boolean append)
  7. writeBytes(File file, byte[] data)
  8. writeBytes(File file, byte[] pattern, int repeat)
  9. writeBytes(File file, byte[] source, int offset, int len)