zoukankan      html  css  js  c++  java
  • Java context replacing with BufferedReader & PrintWriter

     public boolean replacesFileHeader(String strFillFullPath)
        {
            
    boolean bFlag = false;
            
    try{
                    
                File infile 
    = new File(strFillFullPath);   
                BufferedReader in 
    = new BufferedReader(new InputStreamReader( new FileInputStream(infile)));   
                File outfile 
    = new File(infile + ".tmp");  
                PrintWriter out 
    = new PrintWriter(new BufferedWriter(   
                            
    new OutputStreamWriter(new FileOutputStream(outfile))));
                String reading;
            
                
    while ((reading = in.readLine()) != null
                {
                    
    if ((reading.contains("HEADER")) || (reading.contains("DONE")))
                    {
                        
    if (reading.contains("HEADER") )
                        {
                            out.println(
    "HEADER|GSTEST|***|***");
                        } 
    else {
                        
                            out.println(
    "TRAILER|***|DONE");
                        }
                    } 
    else {
                        out.println(reading);
                    }
                                   
                } 
                out.close();   
                in.close();   
                infile.delete();   
                outfile.renameTo(infile);
                
                    bFlag 
    = true;
                } 
    catch (Exception xe) {
                    logTestResult(
    "*Error:"false,xe.getLocalizedMessage());
                    bFlag 
    =  false;
                }
                
    return bFlag;
        }

    - Make people around you successful is the biggest contribution to ourselves. -

  • 相关阅读:
    Python异常详解:基类、具体异常、异常层次结构
    Python视频教程,百度云资源,免费分享
    Python学习路线图(内附14张思维导图)
    Python视频教程免费下载,最新Python免费教程视频分享!
    怎样通过互联网ssh访问家里电脑
    linux下,把屏幕竖起来
    python中函数的不定长参数
    python中全局变量和局部变量
    vbox+Vagrant 入门指南
    python中函数返回多个值
  • 原文地址:https://www.cnblogs.com/zencorn/p/2093569.html
Copyright © 2011-2022 走看看