<%@ 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> 我这样写为什么不对,我是照书写的,搞了好久都不行,请大家闺秀帮帮忙.