How do i read a txt file into a char array. what i have so far only give me blank lines

String fname = "c:\\game.txt";
    char data;
    int row = 2;
        int col = 4;
        char[] matrix = new char[row];

private void openFile()

            FileReader reader = new FileReader(this.fname);

            for (int i=0; i<matrix.length; i++)

        catch(Exception e)
            String s = e.toString();


Of course it does - you aren't saving what is read anywhere:;

If you want the data read into a char[] buffer then you have to supply it as an argument to the read() method. Check the API for read(). There are a few variations available depending on your needs.

i eventually want to read the file into a 2d array. i want to be able to find a particular character in the matrix.

So perhaps you should close this thread, since you have already started another on the exact same topic.

i have a file.txt like this : 2X^2 + 5X+3=0
i want to save 2 to variable a, 5 to variable b, and 3 to variable c . .
how i can do that . . ?
tanks for your help . .

@gunvesxco Please start your own thread with your question. This thread is very old.