日期:2014-05-18  浏览次数:20689 次

请高手帮我看看错在哪儿?
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<%@   page   import   = "java.io.* "   %>
<%!
public   String   codeToString(String   str)
{     String   s=str;
    try
        {
        byte   tempB[]=s.getBytes( "ISO-8859-1 ");
        s=new   String(tempB);
        return   s;
      }
    catch(Exception   e)
      {
        return   s;
      }    
}
%>
<HTML>
<head>
<title> 接收上传的文件 </title>
</head>
<BODY>
<%
String   tempFileName=new   String( "tempFileName1 ");
File   tempFile1=new   File( "D:/ ",tempFileName);
FileOutputStream   outputFile1=new   FileOutputStream(tempFile1);
InputStream   fileSource1=request.getInputStream();
byte   b[]=new   byte[1000];
int   n;
while((n=fileSource1.read(b))!=-1)
        outputFile1.write(b,0,n);
outputFile1.close();
fileSource1.close();
RandomAccessFile   randomFile1=new   RandomAccessFile(tempFile1, "r ");
randomFile1.readLine();
String   FilePath=randomFile1.readLine();
int   position=FilePath.lastIndexOf( '\\ ');
String   fileName=codeToString(FilePath.substring(position+1,FilePath.length()-1));
randomFile1.seek(0);
long     forthEnterPosition=0;
int   forth=1;
while((n=randomFile1.readByte())!=-1&&(forth <=4))    
          if(n== '\n ')
                    {  
                      forthEnterPosition=randomFile1.getFilePointer();
                      forth++;
                      }
File   FileUploadDir=new   File( "d:/tomcat4/webapps/root/ ", "upload ");
FileUploadDir.mkdir();
File   saveFile1=new   File( "d:/tomcat4/webapps/root/upload/ ",fileName);
RandomAccessFile   randomFile2=new   RandomAccessFile(saveFile1, "rw ");  
randomFile1.seek(randomFile1.length());
long   endPosition=randomFile1.getFilePointer();
int   j=1;
while((endPosition> =0)&&(j <=4))
        {
          endPosition--;
          randomFile1.seek(endPosition);
          if(randomFile1.readByte()== '\n ')
                    j++;
        }
randomFile1.seek(forthEnterPosition);
long   startPoint=randomFile1.getFilePointer();
while(startPoint <endPosition-1)
        {
          randomFile2.write(randomFile1.readByte());
          startPoint=randomFile1.getFilePointer();
        }
randomFile2.close();
randomFile1.close();
temp