• 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. -

  • 相关阅读:
    刻舟求剑,
    录制时间是不准确的,
    HIV T2
    DNA RNA
    洛谷 P1428 小鱼比可爱
    Codevs 1081 线段树练习2
    Codevs 1080 线段树联系
    Tarjan算法
    Codevs 2611 观光旅游
    洛谷 1865 A%B问题
  • 原文地址:https://www.cnblogs.com/zencorn/p/2093569.html
Copyright © 2020-2023  润新知