java - How to save console output to a txt file and then display it on the screen right after? -
i kind of confused how write console output txt file , display right after. appreciated. code used far:
public static void savedata(){ try { printstream myconsole = new printstream(new file("result.txt")); system.setout(myconsole); myconsole.print(generatereport()); } catch(filenotfoundexception e){ system.out.println(e); } } public static void displaydata(){ file file = new file("result.txt"); try { scanner input = new scanner(file); while (input.hasnext()){ string num = input.nextline(); system.out.println(num); } } catch(filenotfoundexception e){ system.out.println(e); } }
Comments
Post a Comment