JAVA, how to actually use the data from a text file?
<p>How i can make the code below into the code that is reading from a text file? I know how to read the data from a text file, but im just not sure how i can read it from the text file and also using the data in the algorithm. I have been stuck on this for a long time, hope someone can give me some suggestions what i need to do.</p>

<p>(im posting the question again because the last one i posted wasnt asking the question correctly)</p>

<p>here is the wesite of the algorithm im studying.</p>

<p><a href="http://en.literateprograms.org/index.php?title=Special%3aDownloadCode/Dijkstra%27s_algorithm_%28Java%29&amp;oldid=15444" rel="nofollow">http://en.literateprograms.org/index.php?title=Special%3aDownloadCode/Dijkstra%27s_algorithm_%28Java%29&amp;oldid=15444</a></p>

<pre><code>package dijkstra;

import java.util.List;

public class output {


    public static void main (String[] args){
    Vertex A = new Vertex("england");
    Vertex B = new Vertex("France");
    Vertex C = new Vertex("holland");
    Vertex D = new Vertex("italy");
    Vertex E = new Vertex("portugal");
    Vertex F = new Vertex("iceland");
    Vertex G = new Vertex("Iceland");
    Vertex H = new Vertex("Denmark");
    Vertex I = new Vertex("Norway");
    Vertex J = new Vertex("Finland");
    Vertex K = new Vertex("Sweden");

    A.route = new Edge[]{ 
    new Edge(B, 2),
    new Edge(C, 1),
    new Edge(F, 3),
    new Edge(G, 3)
    };

    B.route = new Edge[]{ 
    new Edge(A, 2),
    new Edge(C, 1),
    new Edge(D, 1),
    new Edge(E, 2),
    new Edge(F, 2)
    };

    C.route = new Edge[]{ 
    new Edge(A, 1),
    new Edge(B, 1),
    new Edge(D, 1),
    new Edge(H, 1),
    new Edge(J, 2)
    };

    D.route = new Edge[]{ 
    new Edge(B, 1),
    new Edge(C, 1),
    new Edge(E, 1),
    new Edge(K, 2)      
    };

    E.route = new Edge[]{ 
    new Edge(F, 3),
    new Edge(B, 2),
    new Edge(D, 1)
    };

    F.route = new Edge[]{
    new Edge(A, 3),
    new Edge(B, 2),
    new Edge(E, 3)
    };

    G.route = new Edge[]{
    new Edge(A, 3)
    };

    H.route = new Edge[]{
    new Edge(C, 1),
    new Edge(I, 1)
    };

    I.route = new Edge[]{
    new Edge(H, 1),
    new Edge(K, 1 )
    };

    J.route = new Edge[]{
    new Edge(K, 1),
    new Edge(C, 2)
    };      

    K.route = new Edge[]{
    new Edge(J, 1), 
    new Edge(D, 2),
    new Edge(I, 1)
    };


Vertex[] vertices = {A,B,C,D,E,F,G,H,I,J,K};

//starting from
Dijkstra.computePaths(G);

for (Vertex v : vertices){  

List&lt;Vertex&gt; p = Dijkstra.getShortestPathTo(v);

//System.out.println( "From " + Vertex.v + " to " + v + ": " + v.minDis);   
System.out.println("Distance : "+ v.minDis);
System.out.println("Shortest Path: "+ p);
System.out.println("---------------------------------------------------------");

}

}
    }
</code></pre>

<hr>

<p>the text file looks like this, meaning the starting point, end point, cost</p>

<pre><code>1 2 2
1 3 1
1 6 3
1 7 3
2 1 2
2 3 1
2 4 1
2 5 2
2 6 2
3 1 1
3 2 1
3 4 1
3 8 1
3 10 2
4 2 1
4 3 1
4 5 1
4 11 2
5 6 3
5 2 2
5 4 1
6 1 3
6 2 2
6 5 3
7 1 3
8 3 1
8 9 1 
9 8 1
9 11 1
10 11 1
10 3 2
11 4 2
11 9 1
11 10 1
</code></pre>

<hr>

<p>another file containing the names of the airports</p>

<pre><code>1 England LHR   
2 France CDG
3 Holland AMS
4 Germany FRA   
5 Italy LIN
6 Portugal LIS
7 Iceland KEF
8 Denmark CPH
9 Norway OSL
10 Finland HEL
11 Sweden ARN
</code></pre>

<hr>

<p>here is the method that i use to read the data</p>

<pre><code>public static void main(String[] args){


     File file = new File("graph.txt");
//   int i = 0 ;

        try {

            Scanner scanner = new Scanner(file); 
            scanner.nextLine(); //ignore the first line
            ArrayList&lt;Nodes&gt; graphList = new ArrayList&lt;Nodes&gt;();

            while (scanner.hasNextLine()) {         

                String line = scanner.nextLine();
                String[] fields = line.split(" ");

                // return it as an integer
                graphList.add(new Nodes(Integer.parseInt(fields[0]),
                                        Integer.parseInt(fields[1]),
                                        Integer.parseInt(fields[2])));
//              i++;
//              if(i==1){
//            
                    System.out.print("From "+fields[0]+" to "+fields[1]+" Cost:"+fields[2] + "\n");
//              }
               // System.out.println("start: "+fields[0]+", end: "+fields[1]+", cost: "+fields[2]);

                }


            scanner.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

}
</code></pre>
