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

Posted on 2009-04-28
Last Modified: 2013-12-14
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

Question by:chandanchoubey
    LVL 92

    Expert Comment

    what garbage are you seeing.
    can u post the txt file

    LVL 6

    Expert Comment

    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?

    Author Comment

    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
    LVL 6

    Accepted Solution

    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()
    LVL 92

    Assisted Solution

    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)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now