?? readfile.java
字號:
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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -