How can I modify this run method to not only print the srting in the output window, but also write to a file for example outfile.txt in project directory. Also each string should be on a separate line in the file.
So I have already created a file in the project directory called outfile.txt
A the moment the code is print fine on window but not printing in the text file
here is the code #
public void run() throws IOException { Scanner sc = new Scanner(System.in); boolean cont = true; while (cont) { System.out.println("Enter text"); String s = sc.nextLine(); if ("*".equals(s)) { cont = false; } else { String result = shorthand(s); System.out.println(result); PrintWriter pw = new PrintWriter("outfile.txt"); pw.println(result); } } }