Java File Object Create toFile(File file, byte[] data)

Here you can find the source of toFile(File file, byte[] data)

Description

Outputs some arbitrary data to file on disk

License

Open Source License

Parameter

Parameter Description
file File to turn into byte[]
data contents of file

Declaration

public static void toFile(File file, byte[] data) 

Method Source Code


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

import java.io.*;

public class Main {
    /**/*from   ww  w  . j  a v  a2  s  .  c  o  m*/
     * Outputs some arbitrary data to file on disk
     *
     * @param file File to turn into byte[]
     * @param data contents of file
     */
    public static void toFile(File file, byte[] data) {
        System.out.println("Attempt create file " + file.getAbsolutePath());
        File parent = file.getParentFile();
        parent.mkdirs();

        //TODO use Box class and do checksum, or shall we?
        BufferedOutputStream outputStream = null;
        try {
            outputStream = new BufferedOutputStream(new FileOutputStream(file));
            outputStream.write(data);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. toFile(Class cls)
  2. toFile(File baseDir, String path)
  3. toFile(File currentDirectory, String file)
  4. toFile(File dir, String[] path)
  5. toFile(File dstPath, String fullClassName)
  6. toFile(IFile file)
  7. toFile(InputStream in, File file)
  8. toFile(InputStream inputStream)
  9. toFile(JavaFileObject javaFileObject)