• Post Reply Bookmark Topic Watch Topic
  • New Topic

is there a way to put this on a text file and read and store it on my array?  RSS feed

 
Alexis Mia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello there I'm new to java and i'm exploring things out on java i've try alot of hours having my problem still no luck
my code is

final static int MAZE_SIZE = 13;
int[][] mazeArray =
{ {0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,1,1,1,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,1,0,1,0},
{0,1,0,0,0,1,1,1,0,1,0,1,0},
{0,1,0,0,0,0,0,0,0,1,0,1,0},
{0,1,0,0,0,1,1,1,1,1,0,1,0},
{0,1,0,1,0,0,0,0,0,0,0,1,0},
{0,1,0,1,1,1,1,1,1,1,1,1,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0}
};

i want it on the file name test.txt when i put those on a test.txt is t possible? and read it and store it on my array list? can you help me with this one? thank you
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and Welcome Alexis,

You could serialize the Object, the deserialize.

I'm not sure if you want the text file to represent the maze, e.g: 0,1,1,0 etc..

Please elaborate.

WP
 
Alexis Mia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:Hello and Welcome Alexis,

You could serialize the Object, the deserialize.

I'm not sure if you want the text file to represent the maze, e.g: 0,1,1,0 etc..

Please elaborate.

WP


can you show me a code for it? and that would be my refereance.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create the maze as a "serializable" object then invoke the correct writers/readers,
you can persist it to a file and recover it.

I would be against this approach though for a number of reasons.

You may just want to iterate through the maze, write it to a File for future reuse.
This would project you against any future updates to the Object/Class when deserialization may fail.

WP
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!