Search code examples
javaswingioinputstreamjtextarea

How to display inputstream in JTextArea?


This is to get stream from server.

BufferedReader fromserver = new BufferedReader(
    new InputStreamReader(client.getInputStream()));

jTextArea1 is the object. How to display the input stream in JTextArea in Java?


Solution

    1. use JTextArea.append() or JTextArea.setText()

    2. use JTextArea.read()

    3. there could be issue with Concurency in Swing, have to invoke XxxStream or XxxReader from Workers Thread, use SwingWorker or Runnable#Thread (all output must be wrapped into invokeLater()),