write Byte data to a file - Android File Input Output

Android examples for File Input Output:Byte Array

Description

write Byte data to a file

Demo Code


//package com.java2s;
import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static boolean writeBytedata(String aFilename, byte[] imgBuffer) {

        FileOutputStream fileOutputStream = null;
        boolean result = true;

        try {// w  w w.  j  av a2s  .  c o  m
            File file = new File(aFilename);
            fileOutputStream = new FileOutputStream(file);
            fileOutputStream.write(imgBuffer);

            fileOutputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            result = false;
        } catch (IOException e2) {
            e2.printStackTrace();
            result = false;
        } finally {
            if (fileOutputStream != null) {
                try {

                    fileOutputStream.close();

                } catch (IOException e) {
                    e.printStackTrace();
                    result = false;
                }
            }
        }

        return result;
    }
}

Related Tutorials