1. Remove the comment
Design a method for removing Java annotation file
Renderings:
. 1 Package IOTest; 2 . 3 Import java.io.BufferedReader; . 4 Import java.io.File; . 5 Import java.io.FileReader; . 6 Import java.io.FileWriter; . 7 Import java.io.IOException; . 8 Import the java.io .PrintWriter; . 9 10 public class Test { . 11 12 is public static void PrintFile (file Newf) { // progressive-entered the print file object 13 is the try (the FileReader fr = new new the FileReader (Newf); the BufferedReader br =new BufferedReader(fr)) { 14 while (true) { 15 String str = br.readLine(); 16 if (str == null) 17 break; 18 System.out.println(str); 19 } 20 } catch (IOException e) { 21 // TODO Auto-generated catch block 22 e.printStackTrace(); 23 } 24 } 25 26 public static voidmain (String [] args) { 27 28 File F = new new File ( "F.: Project \\ \\ \\ javastudy HelloWorld.java the src \\"); // original file F 29 File Newf = new new File ( "F. : Project \\ \\ \\ src \\ HelloWorld2.java javastudy "); // delete contain" // "the newly created file after the line that Newf 30 31 System.out.println (" the original contents of the file are: " ); 32 PrintFile (F); // print the contents of the original document 33 is the try (the FileReader fr = new new the FileReader (F); 34 is FileWriter FW = new new FileWriter (Newf); 35 36 Br = the BufferedReader new new the BufferedReader (fr); // read each line to use the BufferedReader 37 [ the PrintWriter PW = new new the PrintWriter (FW);) { // written in each row use the PrintWriter 38 is // original file f, fr, br; new file Newf, FW, PW 39 the while ( to true ) { 40 String STR = br.readLine (); 41 is IF (STR == null ) 42 is BREAK ; 43 is IF (str.contains ( "//")!) { / / contains annotations, not written, i.e., that the comment line containing "deleted" 44 pw.println (STR); 45 } 46 is 47 } 48 } the catch (IOException E) { 49 // the TODO Auto-Generated Block the catch 50 e.printStackTrace (); 51 is } 52 is System.out.println ( "the new contents of the documents : " ); 53 is PrintFile (Newf); // print file contents 54 } 55 }