HttpClient 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();
}