Search code examples
javaswingiojtextarea

Java:Reading Error


I got problem in reading the file at the Gui text area hopefully you help me out guys to fix the statement of reading file thank you very much

 public static javax.swing.JTextArea jTextArea1;
{
    BufferedReader br = null;

    try {

        String sCurrentLine;

        br = new BufferedReader(new FileReader("C:\\testing1.txt"));

        while ((sCurrentLine = br.readLine()) != null) {
            jTextArea1.read(br, "C:\\testing1.txt"); \\the problem is here
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Solution

  • You can use

     JtextArea1.setText(readtext);
    

    but when you use

     jTextArea1.append(readtext);
    

    that will append data at the end of already read text in jTextArea