how to save to a multi-dimensional array to text file

i have a method to load a text file. other methods then call this method to load the contents of the text file into an array.

code:

static String[][]loadFile()
         {
            JOptionPane.showMessageDialog(null, "TESTING: Inside 'Load File' method");

            String flights[][] = new String[21][5];

            try
               {
                  FileReader file = new FileReader("Assign.txt");
                  BufferedReader buff = new BufferedReader(file);

                  for(int row = 0; row < flights.length; row++)
                     {
                        for(int column = 0; column < 5; column++)
                           {
                              flights[row][column] = buff.readLine();
                           }
                     }
                  buff.close();
               }

            catch(IOException e)
               {
                  System.out.println("Error reading file"+e.toString());
               }

            JOptionPane.showMessageDialog(null, "TESTING: End of 'Load File' method");
             
            return flights;

         }

anyway, as you can see i'm using a file reader to read the file into a buffer and then putting each line the buffer takes into a multi-dimensional array.

what i need to know is how to save to a multi-dimensional array to text file now and overwrite the current contents.

any help is appreciated
kojo12Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yongsingCommented:
try {
  BufferedWriter writer = new BufferedWriter(new FileWriter("Assign.txt", false));
  for(int row = 0; row < flights.length; row++) {
    for(int column = 0; column < 5; column++) {
      String line = flights[row][column];
      writer.write(line, 0, line.length());
      writer.newLine();
    }
  }
  writer.close();
} catch(IOException e) {
  System.out.println("Error reading file"+e.toString());
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
enzogoyCommented:
You just using the FileReader just for reading the file, if you want to save that file into a textfile.  You have to use the PrintWriter, which somehow similar with the File Reader but do the opposite job.

More about the PrintWriter, you may visit the www.sun.com and search for the API.  

Hope it could help you.

cheers

0
CleanupPingCommented:
kojo12:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
jimmackCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept yongsing's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

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.