Sorry if this question has been asked before, but I'm new to coding and I can't find an answer online because I don't know the theory well enough to know how to describe what I'm looking for.
Basically, I want to know if theres a way I can initialize a variable/macro that I can tie to this long try statement, so instead of writing THIS every time I want to read my file
System.out.println("filler");
System.out.println("filler");
try {
FileReader reader = new FileReader("MyFile.txt");
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("filler");
System.out.println("filler");
I can just write something like..
System.out.println("filler");
System.out.println("filler");
Read1
System.out.println("filler");
System.out.println("filler");