Here you can find the source of writeBytes(int[] data, String filename)
Parameter | Description |
---|---|
data | The integer array to write to disk. |
filename | The filename where the data should be written. |
Parameter | Description |
---|---|
IOException | an exception |
public static FileOutputStream writeBytes(int[] data, String filename) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { /**/*from www.j a v a 2 s . c o m*/ * Writes data from the integer array to disk as raw bytes, overwriting the old file if present. * * @param data The integer array to write to disk. * @param filename The filename where the data should be written. * @throws IOException * @return the FileOutputStream on which the bytes were written */ public static FileOutputStream writeBytes(int[] data, String filename) throws IOException { FileOutputStream out = new FileOutputStream(filename, false); writeBytes(data, out); return out; } /** * Writes data from the integer array to disk as raw bytes. * * @param data The integer array to write to disk. * @param out The output stream where the data should be written. * @throws IOException */ public static void writeBytes(int[] data, OutputStream out) throws IOException { byte[] b = new byte[4]; for (int word : data) { b[0] = (byte) ((word >>> 24) & 0xFF); b[1] = (byte) ((word >>> 16) & 0xFF); b[2] = (byte) ((word >>> 8) & 0xFF); b[3] = (byte) ((word >>> 0) & 0xFF); out.write(b); } } }