-5

I have a problem. I want to store a 3D array to a text file. And how could I set the array to the value of a text file?

My array: int mosaics[][][] = new int[100][100][5];

How could I do that?

It absolutely doesn't matters how the text file looks like.

Thanks

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
Levi
  • 13
  • 3
  • If you don't care what formatting, you can write the numbers however you want as long as you can consistently write the same format and parse the input correctly. You could try looking at json for something like this, but it may be easier to just create one long csv (comma separated values) – phflack Dec 18 '15 at 19:24
  • 4
    choose a language first – 463035818_is_not_an_ai Dec 18 '15 at 19:26

1 Answers1

0

If you just want to work with text data and not any binary then the simplest format which comes to my mind is as below

x,y,z:123

In the above format specs, 
x = index of the first
y = index of the second
z = index of the third

To read this you would first -- initialize the value of the full array to nulls or Zero -- read the text file line by line --- split the line on ":" , split the left side with "," comma --- read the individual indexes and set the value for that.

To Write it will be simple as you will be writing the values through the loop. -- to keep the file smaller, you can skip the null.

Jas
  • 336
  • 2
  • 7