FileInputStream转换为byte[]【java】

   File file = new File(filePath);
   FileInputStream in = null;
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   try {
   in = new FileInputStream(file);
   byte[] buffer = new byte[in.available()];
   in.read(buffer);
   out.write(buffer);
   } catch (Exception e) {
   e.printStackTrace();
   } finally {
   try {
   if (in != null)
   in.close();
   } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   }
   }

posted @ 2013-04-09 14:17  郑小明  阅读(15448)  评论(0编辑  收藏  举报