int num=Integer.parseInt((String)m_idea.readOldFile());
m_idea.readOldFile()返回的就是String型
int num=Integer.parseInt(m_idea.readOldFile()); int i=Integer.parseInt(request.getParameter("i"));估计就应该是这两行的其中一行有问题。判断一下m_idea.readOldFile()和request.getParameter("i")对应的指是否为null
<jsp:useBean id="m_idea" class="idea.idea"/>
<%@page import="java.io.*"%>
<%
m_idea.newFilePath="../webapps/guestbook/new.txt";
m_idea.oldFilePath="../webapps/guestbook/old.txt";
m_idea.createFile();
int num=Integer.parseInt(m_idea.readOldFile());
int i=Integer.parseInt(request.getParameter("i"));
m_idea.writeNewFile(num-1);
String m_line="";
for(int j=1;i<5*num+2;j++)
{
m_line=m_idea.readOldFile();
if(j<=5*(i-1)||j>5*i)
{
m_idea.writeNewFile(m_line);
}
}
m_idea.rename();
%>
<script language="JavaScript">
self.location="view.jsp";
</script>
idea.java:
package idea;
import java.io.*;
import java.util.*;
public class idea extends Object
{
public String newFilePath="";
public String oldFilePath="";
private File newFile;
private File oldFile;
private BufferedReader oldFileRead;
private PrintWriter newFileWrite;
public boolean flag=true;
public String systemMessage="";
public void createFile() throws FileNotFoundException
{
newFile=new File(newFilePath);
oldFile=new File(oldFilePath);
oldFileRead=new BufferedReader(new FileReader(oldFilePath));
newFileWrite=new PrintWriter(new FileOutputStream(newFilePath));
}
public void writeNewFile(String writeStr) throws FileNotFoundException
{
newFileWrite.println(writeStr);
}
public void writeNewFile(java.util.Date writeStr) throws FileNotFoundException
{
newFileWrite.println(writeStr);
}
public void writeNewFile(int writeStr) throws FileNotFoundException
{
newFileWrite.println(writeStr);
}
public String readOldFile() throws FileNotFoundException
{
String readStr="";
try
{
readStr=oldFileRead.readLine();
if(readStr.equals("<!--end-->"))
{
flag=false;
}
}
catch(IOException e)
{ flag=false;
}
return readStr;
}
public void rename() throws FileNotFoundException
{
newFileWrite.close();
try
{
oldFileRead.close();
}
catch(IOException e)
{
systemMessage=e.toString();
}
flag=oldFile.delete();
flag=newFile.renameTo(oldFile);
}
}
old.txt:
10
1
[email protected]
11
111<br>111<br>111
2003-8-9 16:16:48
1
[email protected]
11
<<<<<<>>>>&&&<&<<br>
2003-8-9 16:16:14
1
[email protected]
1
1
2003-8-9 15:19:53
dasf
[email protected]
adf
sda
2003-8-9 15:15:29
<sd>
[email protected]
dsd
ad<br>ad<br>sd<br>d
2003-8-9 13:25:00
"'"ss"
[email protected]
"""dsd<br>
adsaa<br>d
2003-8-9 13:16:03
fasdf
[email protected]
adsf
fafffffffffffffffffffffffff
2003-8-9 13:11:27
esa
[email protected]
asdfaa
sf
2003-8-9 13:10:48
sdfs
[email protected]
sfd
sfd
2003-8-9 12:59:19
adsf
[email protected]
adsfa
dafaaaaa
2003-8-8 21:00:36
<!--end-->
int i=Integer.parseInt(request.getParameter("i"));估计就应该是这两行的其中一行有问题。判断一下m_idea.readOldFile()和request.getParameter("i")对应的指是否为null