通过一个http post 如何上传多张图片和图片的描述文字?
解决方案 »
- 写一个ArrayList类的代理,实现和ArrayList中完全相同的功能,并可以计算每个方法运行的时间。
- 订票系统12306的低级问题
- dao层出现空指针异常--初学者求助
- 有返回值的存储过程怎么写啊 ??? 我写的有错误
- axis2客户端调用异常
- j2ee DAO类的接口管理
- java中保存二进制数据的类型是什么?
- 北京思源培训中心&上海加拿大慧桥IT培训中心,我选择了思源培训。
- 大牛来讲一下在java里调用webservices方式吧
- 不能编译类文件问题
- webServices传输数据时发生丢数据现象,本地传输也是,为什么?
- while(rs.next())//为什么这条while只循环了一次?大神求解啊
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
List list = new ArrayList();
list.add("图片和文字");
然后操作这个list!
/**
* <p>文件上传</p>
* @param file File 文件
* @param targetPath String 目标路径
* @param targetFileName String 新文件名
* @return boolean true:成功;false:失败
*/
public static boolean upload(File file, String targetPath, String targetFileName){
boolean flag = false;
File newFile = new File(targetPath + "/" + targetFileName);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(new FileOutputStream(newFile));
byte[] buff = new byte[4096];
int len = 0;
while ((len = bis.read(buff)) != -1){
bos.write(buff);
}
bos.flush();
flag = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bis != null){
bis.close();
bis = null;
}
if (bos != null){
bos.close();
bos = null;
}
} catch (IOException e){
e.printStackTrace();
}
}
return flag;
}