Java Dump Byte Array dumpBytesToFile(byte[] bytes, String outputFile)

Here you can find the source of dumpBytesToFile(byte[] bytes, String outputFile)

Description

dump Bytes To File

License

Open Source License

Declaration

public static void dumpBytesToFile(byte[] bytes, String outputFile) 

Method Source Code


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

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static void dumpBytesToFile(byte[] bytes, String outputFile) {
        try {//from   w w  w .j a v  a 2  s .co m
            BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));

            for (int i = 0; i < bytes.length; ++i) {
                bw.write(getByteAsAscii(bytes[i]));
                if ((i + 1) % 16 == 0) {
                    bw.write("\n");
                }
            }

            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static char getByteAsAscii(byte b) {
        char output = '.';

        if (b > 31) {
            output = (char) b;
        }

        return output;
    }
}

Related

  1. dumpBuffer(final PrintStream out, final String label, final byte[] b)
  2. dumpByteArray(byte[] byteArray)
  3. dumpByteArray(byte[] bytes)
  4. dumpBytes(PrintStream printStream, byte bytes[])
  5. dumpBytesAsString(ByteArrayOutputStream baos)
  6. dumpClass(String file, byte[] bytes)
  7. dumpFileIntoByteArray(File f)
  8. dumpHex(byte[] data)
  9. dumpHex(PrintStream out, byte[] data, int offset, int length)