I have a text file transa.txt .I want the contents of the file to be filled in the array cell by cell.example the file reads:
1 1 1 1 0 0
1 0 1 1 1 1
so i want arr[0][0]=1,arr[0][1]=1,arr[0][2]=1......

Can someone please help me with this..I am stuck with this.

Re: I have a text file what to fill 2d array with its contents 80 80

help you with what exactly? seems to me you 've got it figured out.
all that remains now is to write the actual java code.

Re: I have a text file what to fill 2d array with its contents 80 80

Hi,

You have to do this on two steps : read lines then extract the 1 and 0 after.

// This code isn't ready to be ran, put it in a method
// Openning the file

FileReader fr = new FileReader("transa.txt");
BufferedReader buffer = new BufferedReader(fr);

int digits[][] = new int[NBR_COLUMNS][NBR_ROWS];
int actualLine = 0;

// Reading the file, line by line
String line = buffer.readLine();

while(line != null && !line.equals("")){

    String theDigits[] = line.split(" ");
    for(int i = 0; i < theDigits.lenght; i++){
        digits[actualLine][i] = Integer.parseInt(theDigits[i]);
    }
    actualLine++;
    line = buffer.readLine();

}
Re: I have a text file what to fill 2d array with its contents 80 80

Tarek_2: the point of this forum is not to hand out custom made code, it's to guide and help them write it themselves.

all they can learn from your reply is how to copy paste code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.