我编辑了这段代码因为我无法永久删除它。我编辑了这段代码因为我无法永久删除它。我编辑了这段代码因为我无法永久删除它。我编辑了这段代码因为我无法永久删除它 .i编辑了这段代码因为我不能永久删除它
请不要重新编辑
答案 0 :(得分:1)
您应该从创建图表中将文件加载到图表中。
这样的事情:
public interface GraphLoader {
/**
* Fill a graph with no property from a single file.
*
* @param graph the graph to fill
* @param path path to graph file
* @return a graph with no property
*/
public static void loadSingleFile(Graph graph, Path path) {
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(path.toFile()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
String[] vertices = line.split(" ");
if (vertices.length < 2) {
continue;
}
graph.addEdge(Integer.parseInt(vertices[0]), Integer.parseInt(vertices[1]));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* load a graph with no property from a single file.
*
* @param path path to graph file
* @return a graph with no property
*/
public static Graph loadSingleFile(Path path) {
Graph graph = new Graph();
loadSingleFile(graph, path);
return graph;
}
/**
* load a graph with no property from multiple files in parallel.
*
* @param paths paths to graph files
* @return a graph with no property
*/
static Graph loadMultipleFiles(Path[] paths) {
Graph graph = new Graph();
for (Path path : paths) {
loadSingleFile(graph, path);
}
return graph;
}
}
答案 1 :(得分:0)
按层次顺序划分“catch”块 Advantages of exceptions by Oracle
为什么要使用界面?这是一个建筑理念吗?