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;
    }
posted on 2011-06-29 16:56  zencorn  阅读(244)  评论(0编辑  收藏  举报