1 import java.io.BufferedReader; 2 import java.io.BufferedWriter; 3 import java.io.FileInputStream; 4 import java.io.FileNotFoundException; 5 import java.io.FileWriter; 6 import java.io.IOException; 7 import java.io.InputStreamReader; 8 import java.io.UnsupportedEncodingException; 9 10 public class ReaderAndWriterDome01 { 11 public static void main(String[] args) { 12 String str = "C: \\ Users \\ Administrator \\ Desktop \\ template files - on board material pet.template \\" ; 13 String str1 = "C: \\ the Users Desktop \\ \\ \\ Administrator template file - creative machine 01.txt \\ " ; 14 the BufferedReader Reader = null ; 15 the InputStreamReader ISR = null ; 16 the FileInputStream FIS = null ; . 17 BufferedWriter, Writer = null ; 18 is FileWriter FW = null ; . 19 the try { 20 is FIS = new new the FileInputStream ( str); 21 isr = new InputStreamReader(fis,"UTF-8"); 22 reader = new BufferedReader(isr); 23 24 fw = new FileWriter(str1); 25 writer = new BufferedWriter(fw); 26 StringBuffer sbf = new StringBuffer(); 27 String line = null; 28 while((line = reader.readLine()) != null) { 29 sbf.append(line); 30 } 31 System.out.println ( "replaced by the text:" ); 32 System.out.println (SBF); 33 is 34 is . NewString = sbf.toString String () Replace ( "{name}", "Europe and Europe" ) ; 35 NewString = NewString.replace ( "} {type", "dog" ); 36 NewString = NewString.replace ( "Master {}", "Wei" ); 37 [ System.out.println ( "after replacing the text: " ); 38 is System.out.println (NewString); 39 writer.Write (NewString); 40 writer.flush (); 41 } catch (FileNotFoundException e) { 42 e.printStackTrace(); 43 } catch (UnsupportedEncodingException e) { 44 e.printStackTrace(); 45 } catch (IOException e) { 46 // TODO Auto-generated catch block 47 e.printStackTrace(); 48 }finally{ 49 try { 50 if(reader!=null) 51 reader.close(); 52 if(writer!=null) 53 writer.close(); 54 } catch (IOException e) { 55 e.printStackTrace(); 56 } 57 } 58 } 59 }