欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

哪位高手能帮小弟我看下啊jsp中的文件操作

更新时间: 2014-05-19 01:07:27 责任编辑: Author_N8

 

谁能帮我看下啊!jsp中的文件操作!
比较乱帮忙看看吧!这是做一个文件上传的程序。
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();
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-05-19 01:07:27
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/928862/
本文WWW.DOC100.NET DOC100.NET版权所有。