Here you can find the source of getBytes(File archiveFile)
Parameter | Description |
---|---|
archiveFile | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] getBytes(File archiveFile) throws IOException
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { /**//from www.j a va 2 s. c om * DOC amaumont Comment method "getBytes". * * @param archiveFile * @throws IOException */ public static byte[] getBytes(File archiveFile) throws IOException { long length = archiveFile.length(); int lengthFinalSize = 0; if (length > Integer.MAX_VALUE) { throw new IllegalStateException("Capacity is over !"); } else { lengthFinalSize = (int) length; } FileInputStream fis = new FileInputStream(archiveFile); int bufferSize = 1024; byte[] buf = new byte[bufferSize]; int readBytes = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(lengthFinalSize); while ((readBytes = fis.read(buf)) != -1) { bos.write(buf, 0, readBytes); } return bos.toByteArray(); } }