Java tutorial
//package com.java2s; /** * Copyright JollyTech Limited (c) 2014. All rights reserved. * This software is proprietary to and embodies the confidential * technology of JollyTech Limited. Possession, use, or copying * of this software and media is authorized only pursuant to a * valid written license from JollyTech or an authorized sublicensor. */ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Main { public static byte[] getBytes(String filePath) { byte[] buffer = null; try { File file = new File(filePath); FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(1000); byte[] b = new byte[1000]; int n; while ((n = fis.read(b)) != -1) { bos.write(b, 0, n); } fis.close(); bos.close(); buffer = bos.toByteArray(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return buffer; } }