• java 读取简单文件的内容 InputStreamReader BufferedReader


    // 读取一个.html 文件内容

    public ActionForward editProductProgramaLabel(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws ParseException, UnsupportedEncodingException {
       HttpSession session = request.getSession();
       if(session.getAttribute("managerid")==null){
        return new ActionForward("/manager/sys_manager_login.jsp");
       }
       
       Properties proper = System.getProperties();
       String sep = proper.getProperty("file.separator");
       proper = null;
       // 得到2个部分的路径
       String s_1Path  = request.getRealPath("/") + "home" + sep+ "preview" + sep +"programa_label_1.htm";
       String s_2Path  = request.getRealPath("/") + "home" + sep+ "preview" + sep +"programa_label_2.htm";
       
       BufferedReader br1  = null;
       BufferedReader br2  = null;
       
             File s_1_file  = new File(s_1Path);
             File s_2_file  = new File(s_2Path);
             
             String s_1_content = "";
         String s_2_content = "";
             String test = "";
             try{
              // 读取第一部分
           InputStreamReader  fileReader1 = new InputStreamReader(new FileInputStream(s_1_file) ,"utf-8");  
                 br1 = new BufferedReader(fileReader1);
                
                 while(( test = br1.readLine()) != null)
                 {  
                  s_1_content = s_1_content + test ;
                 }            
                 //读取第二部分
                 InputStreamReader  fileReader2 = new InputStreamReader(new FileInputStream(s_2_file) ,"utf-8");  
                 br2 = new BufferedReader(fileReader2); 
                
                 while(( test = br2.readLine()) != null)  
                 {  
                  s_2_content = s_2_content + test;
                 } 
             }catch(Exception e){
                 e.printStackTrace();
             }finally{
               try{
                   if (br1!=null){             
                     br1.close();
                   }
                   if (br2!=null){              
                     br2.close();
                   }
                 }catch(Exception e){}
             }
             request.setAttribute("content1", s_1_content);
             request.setAttribute("content2", s_2_content);
       request.setAttribute("contextpath", request.getContextPath());
       return new ActionForward("/manager/productProgramaLabel.jsp");
      }

  • 相关阅读:
    13张PPT带你了解主动式消息队列处理集群
    TomatoLog-1.1.0实现ILoggerFactory
    番茄日志发布1.0.3版本-增加Kafka支持
    博客园升级有感一点建议
    上车时机已到--.NETCore是适应时代发展的雄鹰利剑
    花5分钟时间来了解一下高性能网关Kong会有意外收获
    Asp.NETCore让FromServices回来
    高速输出-我们戏说缓存
    Consul-template+nginx实现自动负载均衡
    Consul初探-集成ocelot
  • 原文地址:https://www.cnblogs.com/bailuobo/p/2757337.html
Copyright © 2020-2023  润新知