服务器的代码如下: ServletInputStream inputStream = ((ServletRequest) request)
.getInputStream();
int len, offset, count;
count = offset = 0;
byte[] buffer = new byte[1024]; try {
FileOutputStream outputStream = new FileOutputStream("D:\\123.jpg");
while ((len = inputStream.readLine(buffer, 0, 1024)) != -1) {
offset += len;
outputStream.write(buffer, 0, len);
}
outputStream.flush();
outputStream.close();
} catch (Exception e) {
System.out.println(e.toString());
} PrintWriter out = response.getWriter();
out.println("ok");
.getInputStream();
int len, offset, count;
count = offset = 0;
byte[] buffer = new byte[1024]; try {
FileOutputStream outputStream = new FileOutputStream("D:\\123.jpg");
while ((len = inputStream.readLine(buffer, 0, 1024)) != -1) {
offset += len;
outputStream.write(buffer, 0, len);
}
outputStream.flush();
outputStream.close();
} catch (Exception e) {
System.out.println(e.toString());
} PrintWriter out = response.getWriter();
out.println("ok");
解决方案 »
- 谁有可以正常下载的SDK包啊,还有ADT啊 。。
- 怎么把TextView的背景设置成从黑色到透明渐变?
- surfaceview调用Camera功能和使用Canvas画板
- android 中back键 和home键 个监听的那个函数
- listview嵌套水平listview
- android sqlite支持多少连接?最好开启个连接 谢谢
- 在eclipse里面安装apk时,出现。。
- Android AAPT problem 问题
- 【新手学习】activity跳转后 run()遗留问题
- Android系统是如何获得U盘挂载路径的?
- 向熟悉Android-openGL ES在ndk上的编程的大牛们求教,有一个关于eglGetDisplay的问题纠结很多天了!
- 100分求助:android程序如何调用python脚本
比如Cookie、User-Agent(浏览器类型)等等,具体可以看HTTP头相关的材料
至于要设置什么这个要看服务器端的约定
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
或者
Connection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
有时候你需要给 connection 指定 Content-type。
Content-Type: multipart/mixed header and a multipart body, like this:
Content-Type: multipart/form-data; boundary=[abcdefghijklmnopqrstuvwxyz]
where the boundary specifies the delimiter string between the different parts of the
body.