problems with parsing a text file in Java
<p>I have looked at all the links and cannot seem to get what I am looking for. I have a text file I need to read in. First the text file format:</p>

<pre><code>3 STL NY Chi //all on one line
STL NY 575 //on its own line
NY Chi 550 //on its own line
STL Chi 225 //on its own line
</code></pre>

<p>I need to read the int into an int variable, say we call it count. Then the actual cities on that same line into an array. The next lines need to read into an array to where the mileage is associated with the array, such as [STL NY]=575. I can only use arrays. No hash tables, list, stacks or queues. Here is what I got so far and honestly it isn't much. I could really use some help for I am pretty stumped on the "howto" on this.</p>

<pre><code>import java.io.*;
import java.util.*;

public class P3 {

/**
 * @param args the command line arguments
 */
public static int count;

public static void main(String[] args) {

    try {

        FileInputStream dataFile = new FileInputStream("Data.txt");
        //BufferedReader br = new BufferedReader(new InputStreamReader(dataFile));

        String line = br.readLine();

    }

    catch (IOException e) {
        System.err.println ("Unable to open file");
        System.exit(-1);
    }
  }
}
</code></pre>

<hr>

<p>I think I'm getting there, but I am getting an error code of: "non-static variable cities cannot be referenced from a static context." I am trying to test my code by printing. Can anyone help me with this printing? I would like to see what is in the arrays to make sure I did it correctly. Here is my code:</p>

<pre><code>package p3;

import java.io.*;
import java.util.*;



class citiesDist {
    String cityOne;
    String cityTwo;
    int miles;
}

class city {
    String cityName;
    int numberLinks;
    citiesDist[] citiesDists;
}

public class P3 {

    city[] cities;

    void initCity(int len) {
        for (int i = 0; i &lt; len; i++) {
            cities[i] = new city();
        }
    }

    void initCitiesDist (int index, int len) {
        for (int i = 0; i &lt; len; i++) {
            cities[index].citiesDists[i] = new citiesDist();
        }
    }

    void parseFile() throws FileNotFoundException, IOException { 
        FileInputStream fstream = new FileInputStream("Data.txt"); 
        DataInputStream in = new DataInputStream(fstream); 
        BufferedReader br = new BufferedReader(new InputStreamReader(in)); 

        int numberCities = Integer.parseInt(br.readLine());
        cities = new city[numberCities];
        initCity(numberCities);

        for (int i = 0; i &lt; numberCities; i++) {
            String line = br.readLine();
            int numberLink = Integer.parseInt(line.split(" ")[1]);
            cities[i].cityName = line.split(" ")[0];
            cities[i].numberLinks = numberLink;
            initCitiesDist (i, numberLink);

            for (int j = 0; j &lt; numberLink; j++){
                line = br.readLine();
                cities[i].citiesDists[j].cityOne = line.split(" ")[0];
                cities[i].citiesDists[j].cityTwo = line.split(" ")[1];
                cities[i].citiesDists[j].miles = Integer.parseInt(line.split(" ")[2]);
            }
        }

    }

    public static void main(String args[]) {
        System.out.println("city" + cities.city);
    }
}
</code></pre>
