I need help displaying only text from within a file that begins with lets say the word “Hello” and ends at the word “Bye”. I’m able to scan the whole text file and print it, but I need it to only print out a specific range defined by two variables. This is what I have so far, any tips will be appreciated. Thanks! 🙂
public static void main(String[] args) {
// TODO code application logic here
File fileName = new File("hello.txt");
try {
Scanner scan = new Scanner(fileName);
while (scan.hasNextLine()) {
String line = scan.nextLine();
System.out.println(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
How big is the file? I unless its large, read the file as a string and cut out the bit you want.
Using Apache FileUtils