Return to Snippet

Revision: 25785
at April 9, 2010 01:46 by alejandrosuch


Initial Code
private static byte[] fileToByteArray(String fileName) throws Exception {
		FileInputStream fis = new FileInputStream(fileName);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		
		byte buffer[] = new byte[4096];
		int length = -1;
		
		while (true) {
			length = fis.read(buffer);
			if (length == -1){
				break;
			}
			baos.write(buffer, 0, length);
		}
		
		fis.close();
		
		return baos.toByteArray();
	}

Initial URL

                                

Initial Description

                                

Initial Title
File to byte array

Initial Tags
file, java, array

Initial Language
Java