Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Storing values in a grid

Thread view: 
jason.v2@gmail.com - 25 Sep 2006 22:27 GMT
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.
Brandon McCombs - 25 Sep 2006 23:44 GMT
> Hey guys,
>
[quoted text clipped - 39 lines]
>
> -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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.