<%@ page contentType="text/html; charset=gbk" import="java.io.*"%>
<% /*
InputStream is = request.getInputStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(is));
String buffer = null;
while((buffer = bf.readLine()) != null){
out.println(buffer + "<br>");
}
*/
/*
request.setCharacterEncoding("gbk");
out.println("wawa request value:" + request.getParameter("wawa") + "<br>");
out.println("file request value:" + request.getParameter("file"));
*/
InputStream is = request.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String buffer = null;
while((buffer = br.readLine()) != null){
if(buffer.endsWith("--") && buffer.startsWith("-----------------------------")){
break;
}
if(buffer.startsWith("-----------------------------")){
if(br.readLine().indexOf("filename") > 1){
br.readLine();
br.readLine();
File file = new File(request.getRealPath("/")+ System.currentTimeMillis() + ".txt");
PrintStream ps = new PrintStream(new FileOutputStream(file));
String content = null;
while((content = br.readLine()) != null){
if(content.startsWith("-----------------------------")){
break;
}
ps.println(content);
}
ps.flush();
ps.close();
}
}
}
br.close();
out.println("UpLoad Finished !");
%>
java 实现 文件上传
最新推荐文章于 2024-01-25 15:54:49 发布