创星网络[分享知识 传递快乐]

标题: JSP读文件代码 [打印本页]

作者: luinstein    时间: 2012-12-13 17:26
标题: JSP读文件代码
  1. <%@ page contentType="text/html; charset=gbk" language="java" import="java.io.*" buffer="64kb" %>
  2.       <%

  3.    String path_in = "";
  4.    String content = "";

  5.    path_in = request.getRealPath("/")+"admin"+File.separator+"temp_1.txt";
  6.    out.println(path_in);
  7.   
  8.    try
  9.    {
  10.    BufferedReader in = new BufferedReader (new FileReader(path_in));
  11.    String file = "";
  12.    String temp = "";
  13.    while((temp=in.readLine())!=null)
  14.    {
  15.     file+=temp;
  16.   out.println("writer.println(/""+temp+"/");");
  17.    }
  18.    in.close();
  19.   
  20.    out.println(file);
  21.    out.flush();
  22.    
  23.    
  24.    }
  25.    catch(Exception e)
  26.    {
  27.    out.println(e);
  28.    e.printStackTrace();
  29.    }
  30.    
  31.    
  32.    %>
复制代码
----------

说明:也许你读出来的是未被显示的东西,可以查看网页源代码,完全显示。





欢迎光临 创星网络[分享知识 传递快乐] (http://bbs.cxweb.com.cn/) Powered by Discuz! X3