I have a text file that contains many similar lines to this one
System.out.println(13);
I would like to insert this into my Java code so that when I run the program, it will output 13.
Here is the program where it would just output System.out.println(13);
instead of 13
:
File sampleCode = new File("sample.txt");
try {
Scanner scan = new Scanner(sampleCode);
while(scan.hasNextLine()){
System.out.println(scan.nextLine()); //this is where i plan to insert the lines from the .txt file
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Is it possible?