Page 2 of 2 FirstFirst 12
Results 21 to 21 of 21
  1. #21
    benn22 is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default [SOLVED] Store Text-file Into 2D Array

    I promised I would post up the solution if I ever do figure this out, fortunately I have done just that. ;)

    I've kindly used everyone's suggestion to come about this problem and I am happy to say that not many changes were made. Here is the code:

    Java Code:
    import java.util.*;
    public class FromFile{
    	public static ForestItem[][] fileRead(){
    		Scanner file;
    		String line;
    		int i = 0;
    		ForestItem[][] gridCharArray = new ForestItem[10][10];
    			file = new Scanner(new File("world.txt"));
    			while (file.hasNext()){
    				line = file.nextLine();
    				for (int j=0; j<10; j++){
    					char c = line.charAt(j);
    					if (c == ' ')
    						gridCharArray[i][j] = null;
    						gridCharArray[i][j] = new ForestItem(c);
    		}catch (Exception e){
    			System.out.println("File not found.");
    		return gridCharArray;
    And here is a picture representation:

    Thank you all for being patient with me and I hope I have more questions next time.
    Last edited by benn22; 03-09-2011 at 10:21 PM.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. store data into an array from a file
    By chopo1980 in forum New To Java
    Replies: 10
    Last Post: 11-13-2009, 10:48 AM
  2. Replies: 4
    Last Post: 04-10-2009, 05:35 AM
  3. how to store string in text file
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-03-2009, 06:21 AM
  4. Replies: 3
    Last Post: 04-07-2008, 06:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts