各位老大. 我做了个APPLET 抓取摄相头 然后 上传到 SERVLET ,用的是URLConnection 的OutputStream .可是只能上传10K以下的,大的文件后面的没有传过去.为什么???拜托
解决方案 »
- 下面这个Maven输出是神马意思?
- native2ascii中文默认转换后是什么编码
- xuecheng
- 两个问题:一是如何加密核心java文件,二是如何限制java软件运行时间
- JSP+SERVLET+JAVABEAN+STRUTS+HIBERNENAT+SPRING面试
- 請問jsp或servlet自動刷新
- 新做了一个主页,恳请大家批评!!!!
- 怎样用jsp把数据从数据库中以XML文件得形式读出来?
- 如何使用openssl,要具体的操作步骤。给出即给100分,不要帖没用的文档给我。
- JSP技术论坛试运行
- J2EE~ORACLE高级技术交流平台
- tomcat运行一段时间后,页面打开变得很慢或空白,什么原因?
请各位老大指教啊!!顺便帖上代码
发送端:URL url = new URL(hurl + "?fpath="+fpath+"&sid="+sid+"&uname="+uname+"&number="+pNumber);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setAllowUserInteraction(true); // you may not ask the user
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(true);
conn.setRequestProperty("Content-Type","application/octet-stream");
OutputStream out = conn.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality(1f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(bi);
out.close();
System.out.println(conn.getContentType()+": "+ conn.getResponseCode()); //不知为什么必须这样数据才能发送接收: InputStream in=request.getInputStream();
int len= request.getContentLength();
//ObjectInputStream ins = new ObjectInputStream(in);
byte[] b =new byte[1024*1024];
in.read(b,0,len);
File f = new File(pictPath+fpath);
FileOutputStream fos = new FileOutputStream(f);
fos.write(b,0,len);
System.out.println(len);
in.close();
scdn这点要改进呀。呵呵,顺便把代码贴上。InputStream in=request.getInputStream();
File f = new File(pictPath+fpath);
FileOutputStream fos = new FileOutputStream(f);
//ObjectInputStream ins = new ObjectInputStream(in);
byte[] b =new byte[1024*1024];
int totalBytes, bytes, sumBytes =0;
totalBytes= request.getContentLength();
while(true){
bytes = in.read(b);
if (bytes <=0) break;
sumBytes += bytes;
fos.write(b,0,bytes);
System.out.println ( sumBytes + " of " + totalBytes + " " + ( ( float ) sumBytes/ ( float ) totalBytes ) *100 + "% done" ) ;
}
fos.close();
in.close();