Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: file input to two dimensional array

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default file input to two dimensional array

    I am trying to input file contents into a two dimensional int array. The file consists of multiple rows and columns of chars. I have to apply an if/then to convert the chars to integers, but before I do that, I need to be able to read through the chars in one line, then the next...

    I know how to loop through with hasNextLine, but that only gives me the line as a string and not each char.

    The file looks like this:

    ------..
    ...-----
    ........
    -------

    How do I get the value of each char so I can apply the if/then to dump values into the integer array?

    Should I take each row as a string and parse the chars that way? If so, how?

    Any help would be greatly appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: file input to two dimensional array

    How do I get the value of each char
    If you read each line into a String, the String class has methods to get each character in the String.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    t8ntboy (January 20th, 2013)

Similar Threads

  1. Reading from a text file into a two dimensional array
    By Hayfield in forum File I/O & Other I/O Streams
    Replies: 15
    Last Post: May 13th, 2012, 04:36 PM
  2. How to read a 2 dimensional text file from an array?
    By seaofFire in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 9th, 2012, 07:44 AM
  3. Input in a two Dimensional Array.
    By Mr.777 in forum File I/O & Other I/O Streams
    Replies: 29
    Last Post: December 14th, 2011, 11:40 PM
  4. Read A File and Store Values into a 2-Dimensional Integer Array?
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 9th, 2011, 09:13 PM
  5. How to write 2 dimensional array of float numbers to binary file?
    By Ghuynh in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 17th, 2010, 04:26 PM

Tags for this Thread