比较乱帮忙看看吧!这是做一个文件上传的程序。
Tomcat报错41行有错
38: RandomAccessFile randomFile1=new RandomAccessFile(tempFile1, "r ");
39: randomFile1.readLine();
40: String FilePath=randomFile1.readLine();
41: int position=FilePath.lastIndexOf( '\\ ');
42: String filename=codetoString(FilePath.substring(position+1,FilePath.length()-1));
43: randomFile1.seek(0);
44: long forthEnterPosition=0;
java.lang.NullPointerException org.apache.jsp.accepteuploadfiletest_jsp._jspService(accepteuploadfiletest_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
<%@ page contentType= "text/html; charset=gbk " language= "java " import= "java.io.* " errorPage= " "%>
<%!
public String codetoString(String str)
{
String s=str;
try
{
byte b[]=s.getBytes( "ISO-8859-1 ");
s=new String(b);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<html>
<head>
<title> Untitled Document </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( '\\ '); /*******41行********/
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( "e:/ ", "testupload ");
FileUploadDir.mkdir();
File saveFile1=new File( "e:/ ",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();