日期:2014-05-19 浏览次数:20804 次
FileInputStream input; byte[] buffer = new byte[1024 * 1024]; try { input = new FileInputStream(fileName); int len = input.read(buffer, 0, buffer.length); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
byte[] buf = new byte[1024*1024]; FileInputStream fis = new FileInputStream("c:\\test.db"); int totalLen = 0; //文件总大小 int len = 0; while((len = fis.read(buf)) == buf.length){ totalLen += buf.length; } totalLen += len;
------解决方案--------------------
那你只有把byte[]重新定义大小再传
FileInputStream input; byte[] buffer = null; try { int fileLen = 0; fileLen = input.available(); buffer = new byte[fileLen]; //buffer的大小就是文件的大小 input = new FileInputStream(fileName); int len = input.read(buffer); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
------解决方案--------------------
那个。。。read不是都返回了len嘛。。。。看看doc吧。。。。
------解决方案--------------------
http://topic.csdn.net/u/20120816/17/963e96cd-4476-41c4-88fb-b7a1d2a958ba.html