<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=gb2312
"
%>
<% @ page import = " java.io.* " %>
<! DOCTYPE html PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN " " http://www.w3.org/TR/html4/loose.dtd " >
< html >
< head >
< title > 分页读取文件内容 </ title >
</ head >
< body >
< p align = " center " > 分页读取内容: </ p >
< p >
<%
String pages = request.getParameter( " page " );
if (pages == null )
... {
pages="0";
}
int diPage = Integer.parseInt(pages);
%>
<%
int pageFileSize = 20 ;
int fileLineCount = 0 ;
int fileCountPage = 0 ;
File f = new File( " c:/test.doc " );
// 得到文件总行数
if (f.exists())
... {
FileReader fileReader1=new FileReader(f);
BufferedReader bf=new BufferedReader(fileReader1);
String tempString=null;
while((tempString=bf.readLine())!=null)
...{
fileLineCount++;
}
bf.close();
fileReader1.close();
}
// 得到文件页数
if (fileLineCount % pageFileSize == 0 )
fileCountPage = fileLineCount / pageFileSize;
else
fileCountPage = fileLineCount / pageFileSize + 1 ;
// 读取当前页面的文件内容
if (f.exists())
... {
FileReader fileReader1=new FileReader(f);
BufferedReader bf=new BufferedReader(fileReader1);
String tempString=null;
for(int i=0;i<diPage*pageFileSize;i++)
bf.readLine();
for(int i=0;i<pageFileSize && (tempString=bf.readLine())!=null;i++)
out.println(tempString+"<br>");
bf.close();
fileReader1.close();
}
else
... {
out.println("文件中暂时没有内容.");
}
%>
</ p >
< p align = " center " >
<%
if (diPage > 0 )
... {%>
<a href="fenye.jsp?page=<%=diPage-1 %>">上一页</a>
<% } %>
<%
if (diPage < fileCountPage)
... {%>
<a href="fenye.jsp?page=<%=diPage+1 %>">下一页</a>共<%=fileCountPage %>页,当前第<%=diPage+1 %>页
<%} %>
</ p >
</ body >
</ html >
<% @ page import = " java.io.* " %>
<! DOCTYPE html PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN " " http://www.w3.org/TR/html4/loose.dtd " >
< html >
< head >
< title > 分页读取文件内容 </ title >
</ head >
< body >
< p align = " center " > 分页读取内容: </ p >
< p >
<%
String pages = request.getParameter( " page " );
if (pages == null )
... {
pages="0";
}
int diPage = Integer.parseInt(pages);
%>
<%
int pageFileSize = 20 ;
int fileLineCount = 0 ;
int fileCountPage = 0 ;
File f = new File( " c:/test.doc " );
// 得到文件总行数
if (f.exists())
... {
FileReader fileReader1=new FileReader(f);
BufferedReader bf=new BufferedReader(fileReader1);
String tempString=null;
while((tempString=bf.readLine())!=null)
...{
fileLineCount++;
}
bf.close();
fileReader1.close();
}
// 得到文件页数
if (fileLineCount % pageFileSize == 0 )
fileCountPage = fileLineCount / pageFileSize;
else
fileCountPage = fileLineCount / pageFileSize + 1 ;
// 读取当前页面的文件内容
if (f.exists())
... {
FileReader fileReader1=new FileReader(f);
BufferedReader bf=new BufferedReader(fileReader1);
String tempString=null;
for(int i=0;i<diPage*pageFileSize;i++)
bf.readLine();
for(int i=0;i<pageFileSize && (tempString=bf.readLine())!=null;i++)
out.println(tempString+"<br>");
bf.close();
fileReader1.close();
}
else
... {
out.println("文件中暂时没有内容.");
}
%>
</ p >
< p align = " center " >
<%
if (diPage > 0 )
... {%>
<a href="fenye.jsp?page=<%=diPage-1 %>">上一页</a>
<% } %>
<%
if (diPage < fileCountPage)
... {%>
<a href="fenye.jsp?page=<%=diPage+1 %>">下一页</a>共<%=fileCountPage %>页,当前第<%=diPage+1 %>页
<%} %>
</ p >
</ body >
</ html >