社区
Web 开发
帖子详情
在servlet中ServletInputStream的方法readLine怎么用?
twinkle_wy
2001-07-15 04:55:05
怎么用他实现读出一行字符?
...全文
182
回复
打赏
收藏
在servlet中ServletInputStream的方法readLine怎么用?
怎么用他实现读出一行字符?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
原理讲解-
Servlet
InputStream
.
readLine
(byte[] b, int off, int len)
方法
原理讲解-
Servlet
InputStream
.
readLine
(byte[] b, int off, int len)
方法
原理讲解-
Servlet
InputStream
.
readLine
(byte[] b, int off, int len)
方法
jspblog项目
package com.scce.
servlet
; import java.io.FileOutputStream; import java.io.IOException; import javax.
servlet
.
Servlet
Exception; import javax.
servlet
.
Servlet
InputStream
; import javax.
servlet
.http.Http
Servlet
; import javax.
servlet
.http.Http
Servlet
Request; import javax.
servlet
.http.Http
Servlet
Response; public class Photo
Servlet
extends Http
Servlet
{ public void doGet(Http
Servlet
Request request, Http
Servlet
Response response) throws
Servlet
Exception, IOException { this.doPost(request, response); } public void doPost(Http
Servlet
Request request, Http
Servlet
Response response) throws
Servlet
Exception, IOException { String type=request.getParameter("myType"); String encoding="UTF-8"; if(type.equals("upload")){
Servlet
InputStream
sis=request.get
InputStream
(); int len=request.getContentLength(); int index=0; String tmp=null; boolean isFirst=true; String firstLine=null; int [] iindex=new int[1]; byte[] bytes=new byte[4096]; String filename=null; while((tmp=
readLine
(bytes,iindex,sis,encoding))!=null){ if(isFirst){ firstLine=tmp; isFirst=false; } index=tmp.indexOf("finename="); if(index!=-1){ String tailString = tmp.substring(index+10); if(tailString != null){ int ii=tailString.indexOf("\""); filename=tailString.substring(0,ii); } System.out.println(tmp); break; } filename=getName(filename); if(filename!=null){ filename="file.out1"; } String filepath="e:/"+filename; FileOutputStream fos=new FileOutputStream(filepath); String endFlag=firstLine.substring(0,firstLine.length()-2)+"--"+firstLine.substring(firstLine.length()-2); String contentType=
readLine
(bytes,iindex,sis,encoding); if(contentType!=null){ if(contentType.indexOf("Content-Type")==-1){ System.out.println(contentType); }else{ System.out.println("the head of file:"+
readLine
(bytes,iindex,sis,encoding)); } } boolean tt=false; int mark=0; byte[] backups=new byte[4096]; while((tmp=
readLine
(backups,iindex,sis,encoding))!=null){ if(endFlag.equals(tmp)){ if(mark>2){ fos.write(backups,0,mark-2); fos.flush(); } break; }else{ if(tt){ fos.write(backups,0,mark); fos.flush(); } mark=iindex[0]; for(int i=0;i
readLine(byte[] bytes, int[] index,
Servlet
InputStream
sis, String encoding) { try{ index[0]=sis.
readLine
(bytes, 0, bytes.length); if(index[0]<0){ return null; } }catch(IOException ex){ ex.printStackTrace(); } try{ if(encoding==null){ return new String(bytes,0,index[0]); }else{ return new String(bytes,0,index[0],encoding); } }catch(Exception e){ e.printStackTrace(); return null; } } }
JavaIO流精讲上
课程内容主要有:File类概述、File类功能讲解、JAVA IO流概述、字节流、字符流、缓冲流、
InputStream
、OutputStream、Reader、Writer、File
InputStream
、FileOutputStream、
InputStream
Reader、OutputStreamWriter、...
java
中
用javax.
servlet
.
Servlet
InputStream
.
readLine
有什么安全问题吗?怎么解决实例?
java
中
用javax.
servlet
.
Servlet
InputStream
.
readLine
有什么安全问题吗?怎么解决实例?
Tomcat_
Servlet
InputStream
#
readLine
读取一行数据
InputStream
读取一行字符串 //输入流读取一行字符串 public int
readLine
(byte[] b,int off,int len) throws IOException { //如果内容长度小于等于0,直接返回0 if(len<=0) { return 0; } //count统计当前读到的位置 // c读取Byte值 int count = 0,c; //逐字节读取内容 while((c=read())!=-1) { //
Web 开发
81,092
社区成员
341,716
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章