readfile.java
来自「This code implements the shortest path a」· Java 代码 · 共 54 行
JAVA
54 行
import java.io.*;
import java.util.StringTokenizer;
public class ReadFile {
public AdjGraph graph;
public int linect=-1;
//count the number of lines in the data file
public ReadFile(String filename){
graph = new AdjGraph(1000);
int readin[]=new int[3];
try
{ //read from file and store the data into a adjacent graph G
BufferedReader inputStream =
new BufferedReader(new FileReader(filename));
String line = null;
line = inputStream.readLine();
while(line.compareTo("*")!=0){
linect++;
int i=0;
StringTokenizer T = new StringTokenizer(line);
while (T.hasMoreTokens()){
readin[i]=Integer.valueOf(T.nextToken()).intValue();
i++;
}
if (i<2) graph.setSource(readin[0]);
else graph.addNode(readin[0], readin[1], readin[2]);
line = inputStream.readLine();
}
}
catch(FileNotFoundException e)
{
System.out.println("Data file was not found");
System.out.println("or could not be opened.");
}
catch(IOException e)
{
System.out.println("Error reading from file.");
}
}
public AdjGraph getGraph(){
//return the graph
return graph;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?