Question: How to properly read a text file and use a delimiter to read the comments of a Java Source File Expected Output after moving a
How to properly read a text file and use a delimiter to read the comments of a Java Source File
Expected Output after moving a java source file:
Comment Scrape -
1: /*****************************************
2: ** This is my program // Weird comment! **
3: *****************************************/
7: /* Amount available */
14: /* This is my code */
What I have so far..
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner kb = new Scanner(System.in);
System.out.println("Please enter the file name: ");
String sourceFile = kb.nextLine();
// Scanner in = new Scanner(new File(sourceFile));
try {
Scanner in = new Scanner(new File(sourceFile));
String txtFile = sourceFile + ".txt";
PrintWriter fileOut = new PrintWriter(txtFile);
while(in.hasNextLine()) {
String intoTxt = in.nextLine();
fileOut.print(intoTxt);
fileOut.println("");
}
fileOut.close();
File file = new File(txtFile);
int lineNum = 0;
Scanner text = new Scanner(file);
while(text.hasNextLine()) {
} // HERE IS MY PROBLEM. HOW DO I LOOK A TEXT FILE AND MANIPULATE THE STRING TO READ ONLY COMMENTS OF THE JAVA SOURCE FILE
}
catch (FileNotFoundException e) {
System.out.println("Sorry that file does not exist or is not accessible.");
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
