I have created a thread that should allow the user to input a string of characters into the command line and this should save, on a new line, to a file, called user_input.txt.
I managed to make it work while on the main thread, but I need to make it happen within a Thread.
Here is my code for the Thread object:

//Importing//Inputimport java.io.InputStreamReader;import java.io.BufferedReader;import java.io.IOException;//File writingimport java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;public class FileInputThread implements Runnable{ public void run() { System.out.println("FileInputThread running"); //Creating Instances of InputStreamReader and BufferedReader InputStreamReader input = new InputStreamReader(System.in); BufferedReader keyboardInput = new BufferedReader(input); //Finding/Creating File File file = new File("/Users/jakecarr/Documents/University/Year 2/Semester 1" + "/ECM2414 Software Development/Workshop 3/user_input.txt"); try { // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } //Creating instances of FileWriter and BufferedWriter FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); //Creating Date object Date date; //Output System.out.println("Type what you want to write to file"); System.out.println("Please type 'ESC' to exit"); while (true) { System.out.println("Inside While loop"); String string = keyboardInput.readLine(); //Checks if user types in ESC to stop program if (string.equals("ESC")) { System.out.println("You are finished"); break; } //Writing the input to the file bw.write(string); bw.newLine(); //Flushes strings on buffered reader to the hard drive bw.flush(); } System.out.println("Writing to file complete"); } catch(IOException e) { System.out.println(e.getMessage()); } }}Right now, it seems to do all the println methods, I just doesn't allow you to type anything in at the command line when it comes to the keyboardInput.readLine(); and that is where it seems to get stuck!
I would be grateful for any help!
Thank you.

Check Solution