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.

Recommended Answers

All 3 Replies

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.

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();

}

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.