how do I read a file in notepad after saving it through a java program

I am writing some data through a java .jar file on to a disc. How do I read the saved file in a notepad? It shows lot of grabage when I open the file in notepad. Here is my code
        path = myFileChooser.getSelectedFile().getPath();
        String data = dataDisplay.getText();
        PrintWriter outdata = new PrintWriter
                (new FileWriter(path));
        catch (IOException err1)
            dataDisplay.append("problem saving Object to disc:"
                    +err1.getMessage()+ '\n');
        catch(Exception err2)
    private void mnuOpenActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // Loading already saved data handling code here:
        path = myFileChooser.getSelectedFile().getPath();
            BufferedReader inmyFile = new BufferedReader(new FileReader(path));
catch(Exception err3)
            dataDisplay.append("\nError loading array" + err3.getMessage()+'\n');

Open in new window

Who is Participating?
__geof__Connect With a Mentor Commented:
Did you get the ouput of dataDisplay.getText()? In a debug console or System.out.println(dataDisplay.getText());

It looks almost correct to me. What are you expecting in there? The result of the calculation? It looks like it prints the calculation itself so it sems that you should look into dataDisplay.getText()
what garbage are you seeing.
can u post the txt file

2 things that can be wrong:
1. dataDisplay.getText(); does not return a readable String. I would check if your data variable holds some text that you can read
2. Notepad doesn't understand that your file is a text file. Does the file have .txt extension? Do you have the same problem in WordPad?
chandanchoubeyAuthor Commented:
The program is actually a calculator, all numbers which are added, subtracted, multiplied or divided are displayed in a text area (dataDisplay). I am saving all numbers using FileWriter. When I open the saved file in notepad it comes something like following
’ t +6
objectsConnect With a Mentor Commented:
the problem is in your textarea and not your file by the looks
check you aren't adding junk to the text area (as I posted in your previous q)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.