Storing values in a grid

J

jason.v2

Hey guys,

This is my first time using this so I guess we'll see how this goes.

I have a text file, input.txt that is a block of character that looks
something like this:

A S D F G H I
T Y E W F H E
P K L O F V B

What I'm trying to do is something like this:

Grid G = null;
BufferedReader input = null;

try{
input = new BufferedReader(new FileReader("input.txt"));
String line;
int counter = 0;
char[] tmp = new char[20];}

while((line = input.readLine()) != null){
counter++;}

for(int i=0; i<=G.getRow(); i++)
{
for(int j=0; j<=G.getCol(); j++)
{
input.read(tmp[], 0, 1);
}
}
}

There is a catch block after this to catch IO exception and File Not
Found Exception. I'm not sure how to take the characters from input.txt
and put them into the Grid, G.

I would really appreciate any help you guys might have....

Thanks!

-Jason.
 
B

Brandon McCombs

Hey guys,

This is my first time using this so I guess we'll see how this goes.

I have a text file, input.txt that is a block of character that looks
something like this:

A S D F G H I
T Y E W F H E
P K L O F V B

What I'm trying to do is something like this:

Grid G = null;
BufferedReader input = null;

try{
input = new BufferedReader(new FileReader("input.txt"));
String line;
int counter = 0;
char[] tmp = new char[20];}

while((line = input.readLine()) != null){
counter++;}

for(int i=0; i<=G.getRow(); i++)
{
for(int j=0; j<=G.getCol(); j++)
{
input.read(tmp[], 0, 1);
}
}
}

There is a catch block after this to catch IO exception and File Not
Found Exception. I'm not sure how to take the characters from input.txt
and put them into the Grid, G.

I would really appreciate any help you guys might have....

Thanks!

-Jason.

First you need to actually create your Grid because you set G to null
and don't do anything else with it as far as creating it so don't forget
to do that.

Second, once you do that just take the line variable and call
line.split(" "); which will split each line using a space as the
delimiter. At that point you can do whatever you want with the
individual characters since they will be separated within an array. I
don't know what Grid is (and I don't se it in the JDK class list for
Java2 1.5) so I can't say what you will need to do to get the values
into your Grid but you should be able to figure it out at that point.

Not knowing anything about your Grid class I have to wonder why you
aren't using a 2D array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top