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.

4 Years
Discussion Span
Last Post by stultuske

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.



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]);
    line = buffer.readLine();


Edited by Tarek_2


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.