当前位置: 代码迷 >> Java Web开发 >> [求助]上传文件代码????
  详细解决方案

[求助]上传文件代码????

热度:299   发布时间:2005-09-10 07:14:00.0
[求助]上传文件代码????
急要知道JSP上传文件到文件夹的代码,不用很复杂,简单的就行
搜索更多相关主题的帖子: 文件  代码  

----------------解决方案--------------------------------------------------------
对了,我用的是TOMCAT5.0
----------------解决方案--------------------------------------------------------

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <%@ page import="java.io.*"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>up</title> </head>

<body> <% try{ InputStream in=request.getInputStream(); String path=request.getRealPath("/"); File f1=new File(path+"/zht/admin","b.txt"); FileOutputStream o=new FileOutputStream(f1); byte b[]=new byte[10000]; int n; while((n=in.read(b))!=-1) { o.write(b,0,n); } o.close(); in.close();

RandomAccessFile random=new RandomAccessFile(f1,"r"); random.seek(0); long forthEndPosition=0; int forth=1; while((n=random.readByte())!=-1&&(forth<=4)) { if(n=='\n') { forthEndPosition=random.getFilePointer(); forth++; } } File f2=new File(path+"/zht/admin","c.gif"); RandomAccessFile random2=new RandomAccessFile(f2,"rw"); random.seek(random.length()); long endPosition=random.getFilePointer(); long mark=endPosition; int j=1; while((mark>=0) && (j<=6)) { mark--; random.seek(mark); n=random.readByte(); if(n=='\n') { endPosition=random.getFilePointer(); j++; } } random.seek(forthEndPosition); long startPoint=random.getFilePointer(); while(startPoint<endPosition-1); { n=random.readByte(); random2.write(n); startPoint=random.getFilePointer(); } random2.close(); random.close(); //f1.delete(); out.print("OK!"); } catch(IOException ee){out.print("fail!");} %> </body> </html> 我这样写为什么不对,我是照书写的,搞了好久都不行,请大家闺秀帮帮忙.


----------------解决方案--------------------------------------------------------
  相关解决方案