代码呈现如下:
package graph;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class GraphRepresentation {
static int vertexNum;
static int arcNum;
static int matrix[][];
public static void main(String[] args) {
try {
File file = new File("src/tinyG.txt");
InputStreamReader reader = new InputStreamReader(
new FileInputStream(file));
BufferedReader bufferedreader = new BufferedReader(reader);
int index = 1;
String str = "";
while ((str = bufferedreader.readLine()) != null) {
if (index == 1) { // 读取第一行数字,并作为顶点数附值给vertexNum
vertexNum = Integer.parseInt(str.trim());
index++;
System.out.print("获取图的顶点数为:" + vertexNum + "\n&