I have a .data file that looks like this:

![Data](https://i.stack.imgur.com/e29oe.png) 

I want my main method to be able to read the file and store it into a 2-dimensional int array, there is a "?" in the data I want it to be converted to a 0.

I have this code so far, but it doesn't work and I get a null pointer exception (probably from initializing my 2-d array to null). The problem is if I don't initialize my 2-d array to null it gives me errors **EDIT**(this answers part of the problem, but how can I get java to get the size of the number of rows in the data and then initialize dataSet to int[number of rows][numbers in each row], I can't even get java to read the file in the first place)

```
public static void main(String[] args){

    int[][] dataSet = null;

    try {
        Scanner inFile = new Scanner(new File("C:\\Data Folder\\file.data"));

        while (inFile.hasNextInt()){
            for (int i = 0; i < dataSet.length; i++){
                for (int j = 0; j < dataSet[i].length;){
                    dataSet[i][j] = inFile.nextInt();
                }
                System.out.println(dataSet[i]);
            }

        }

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

```

I have never tinkered around with files on Java so this is all new to me.

Any advice is appreciated

**EDIT: 3:11 p.m.**

So I changed my 2-d array to array list instead, thanks Masud:

```
public static void main(String[] args){

    List<Integer> dataSet;

    try {
        Scanner inFile = new Scanner(new File("C:\\Data Folder\\file.data"));

        while (inFile.hasNextInt()){
            for (int i = 0; i < dataSet.size(); i++){
                dataSet.add(inFile.nextInt());
            }

        }

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

```

Eclipse is still asking me to set dataSet = null. How would I get the size of the number of rows and number of numbers in each row from the .data file?

**EDIT: 3:23 pm**

Thank you Merlin for implementing Masud's suggestion, I have updated my main method to represent your code just to see if it works. I keep getting this error:

```
Exception in thread "main" java.lang.NumberFormatException: For input string: "1 15943882 63 1 -9 -9 -9"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)

```

Here is the code that I used:

```
public static void main(String[] args){

    List<int[]> dataSet = new ArrayList<int[]>();

    try {
        Scanner inFile = new Scanner(new File("C:\\Data Folder\\file.data"));

        while (inFile.hasNextLine()){
            String line = inFile.nextLine();
            String[] cols = line.split(",");
            int[] rows = new int[cols.length];
            for (int i = 0; i < cols.length; i++){
                if (!cols[i].equals("?")){
                    rows[i] = Integer.parseInt(cols[i]);
                }
                else {
                    rows[i] = 0;
                }
            }
            dataSet.add(rows);
            }
        System.out.println(dataSet.size());

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

```

It also tell me add "@suppress warning" to inFile.

**EDIT**

I fixed the error by changing the file path to a processed data file, sorry about that that's my fault. Merlin and Masud thank you for the guidance!