0

私のコード:

JFileChooser opChooser=new JFileChooser();
            FileNameExtensionFilter filter=new FileNameExtensionFilter("XML File", "xml");
            opChooser.setFileFilter(filter);
            int returnVal=opChooser.showOpenDialog(null);
            File chosenFile=opChooser.getSelectedFile();

            try
            {
                if (returnVal==JFileChooser.APPROVE_OPTION)
                {
                    BufferedReader br=new BufferedReader(new FileReader(chosenFile));
                    currentDirectory="";
                    textPane.setText("");
                    textPaneError.setText("");
                    currentDirectory=chosenFile.getAbsolutePath();

                    String data = "";
                    while ((br.readLine())!=null)
                    {
                        data += br.readLine();
                    }
                    doc.insertString(0, data, null);
                    br.close();
                }
            }
            catch (IOException | BadLocationException ex)
            {
                JOptionPane.showMessageDialog(null, "ERROR!!!");
            }
        }

アプリで開きたいxmlファイル:

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

結果:

<from>Jani</from><body>Don't forget me this weekend!</body>null

結果がxmlファイルのようにならない理由を誰かが説明してくれたらありがたいです。最初の 2 行はどこにあり、最後に挿入された文字列が null なのはなぜですか?

4

1 に答える 1