When writing a program in Java, and you want to read a file, is there a way the USER can have the program completely ignore certain lines or characters by making the certain file’s line or character into more of a ‘comment’? Just as a programmer can use ‘//’ or ‘/* */’ while programming.
Share
You can skip the lines that start with a certain pattern (e.g. ‘//’ or ‘#’).
There’s an example on how to read a file in Java line by line here: http://www.roseindia.net/Java/beginners/java-read-file-line-by-line.shtml
You can change the while-loop like this:
In this example lines starting with ‘#’ will not get printed.