小小cheng婿员
2017-06-30 08:50java IO在写入文件的时候到了8192字节以后就报异常
50HttpClient httpclient = new HttpClient();
File file = new File("D:\\cirros-0.3.4-x86_64-disk.img");//一个本地20多M的假镜像
PutMethod put = new PutMethod("");//我使用httpclient3.1传输文件
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
//下面是将文件写入http的(OutputStream) put.getRequestEntity()中
bos = new BufferedOutputStream((OutputStream) put.getRequestEntity());
try {
bis = new BufferedInputStream(new FileInputStream(file));
byte[] buff = new byte[1024];
int i;
while ((i = bis.read(buff)) >= 0) {//这里前8次写入都没问题,到了第九次就会报异常了 异常是空指针,什么鬼呢?新手勿喷各位大神
bos.write(buff, 0, i);
}
} catch (IOException e) {
e.printStackTrace();
}
- 点赞
- 回答
- 收藏
- 复制链接分享
4条回答
为你推荐
- 安卓开发 java.lang.RuntimeException: Unable to start activity ComponentInfo{(xxx)}: java.lang.NullPointerException
- android
- 1个回答
- java io流的问题
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- 精通Socket的朋友请进~~~紧急求援啊!
- spring
- 0个回答
- JAVA编写HTTP下载遇到难题了,望各位给个思路
- swing
- 0个回答
- 用java实现:上传excl表格。读取数据,输出结果。
- java
- 数据
- 7个回答
换一换