解决方案 »
- android开发如何利用图片实现VidoGroup的类似功能
- 自动完成框Adapter构造函数的第二个参数
- 如何获取Android系统时间是24小时制还是12小时制
- view如何获取键盘事件。
- 免费下载游戏开发工具集CocoStudio v0.1.5
- 怎么让linearlayout在动态添加图片显示的时候,始终只显示五个,每次添加图片后,自动水平移动,屏幕中间值显示五个图片。
- android 显示 圆形图片
- ListView获取指定的item,然后去除它的分割线,困扰俩天了,求解
- android kotlin mvp转化问题
- 摄像头遮挡提示的原理是什么
- 怎样在其他应用上实现浮层
- 关于onPause()和onSaveInstanceState()的疑惑
而我自己用servlet简单写了个验证. 发现我的上传文件名字是没问题的. 是XX.mp3或xx.jpg的
new Thread(){
public void run() {
String end = "\r\n";
String twoHyphens = "--";
String boundary = "******";
try
{
URL url = new URL(uploadUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setChunkedStreamingMode(128 * 1024);// 128K
// 允许输入输出流
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
// 使用POST方法
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("Charset", "UTF-8");
httpURLConnection.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + boundary); DataOutputStream dos = new DataOutputStream(
httpURLConnection.getOutputStream());
dos.writeBytes(twoHyphens + boundary + end);
dos.writeBytes("Content-Disposition: form-data; name=\""+uploadedfile+"\"; filename=\""
+ srcPath.substring(srcPath.lastIndexOf("/") + 1)
+ "\""
+ end);
dos.writeBytes(end);
FileInputStream fis = new FileInputStream(srcPath);
byte[] buffer = new byte[8*1024]; // 8k
int count = 0;
// 读取文件
while ((count = fis.read(buffer)) != -1)
{
dos.write(buffer, 0, count);
}
fis.close(); dos.writeBytes(end);
dos.writeBytes(twoHyphens + boundary + twoHyphens + end);
dos.flush(); InputStream is = httpURLConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "utf-8");
BufferedReader br = new BufferedReader(isr);
String result = br.readLine();
System.out.println(result);
handler.sendEmptyMessage(1);
dos.close();
is.close(); } catch (Exception e)
{
e.printStackTrace();
}
};
}.start();
}这个是拼装方法