If your 'The background to this short story in' part is not changing in every line then you may use pattern matching to get the new word .
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String args[]) {
// String to be scanned to find the pattern.
String pattern = "The background to this short story in (.*)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
String file = "fileLocation";
try (BufferedReader br = new BufferedReader(new FileReader(file ))) {
String line;
while ((line = br.readLine()) != null) {
Matcher m = r.matcher(line);
if (m.find()) {
System.out.println("Found value: " + m.group(0));
System.out.println("Found value: " + m.group(1)); // GIVES YOU THE NEW WORD
} else {
System.out.println("NO MATCH");
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
You will get the new word in m.group(1) .