Posted on 1998-07-31
Last Modified: 2010-03-30
Is there anyway of sending a 2-d array to a file????
Question by:alanmin
  • 2
  • 2

Accepted Solution

mjenkins earned 10 total points
ID: 1229801
There is really no direct support for two dimensional arrays in Java. What you are really dealing with is an array of arrays.

So to write the whole thing to a file, just iterate through the outside array and each of the contained arrays in order.

Author Comment

ID: 1229802
What i really need to know though is how to send it to a file.

Expert Comment

ID: 1229803
You didn't specify what kind of array it is. Is it an array of
primative types, or object? In either case, you can use a DataOutputStream ans just iterate through the tow arrays:

for( int i= 0; i < array.length; i++ )
      for( int j = 0; j < array[i].length; j++ )
            ostream.writeInt( array[i][j] );

Author Comment

ID: 1229804
got it sorted anyway ta!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

911 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

15 Experts available now in Live!

Get 1:1 Help Now