How do I put the while loop into the thread?

public class Weather { public static void main(String[] args) throws UnknownHostException, IOException { String host = ""; int port = 3000; int byteOfData; { try (Socket socket = new Socket(host, port); InputStream inputStream = socket.getInputStream(); OutputStream ouputStream = socket.getOutputStream(); PrintWriter printWriter = new PrintWriter(socket.getOutputStream(), true); final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( { //also, a thread for reading from stdin Thread remoteOutputStream = new Thread() { @Override public void run() { //while loop should go here // Socket closed //why does this error occur? } }; remoteOutputStream.start(); while ((byteOfData = != -1) { //put into thread out.print((char) byteOfData); } } } }}when I put the while loop into the thread, it just throws Socket closed because, presumably, of how try with resources works. However, I don't know how to use a thread with this kind of try.

Check Solution