Java Dosyadan Okunan Graphı Matrise Atama

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class ReadGraph {

public static void main(String[] args) {
String[][] dizi = new String[8][3];

try {
File f = new File("graph.txt");
FileReader fr;
fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String satir;
int j = 0;
try {
// bos satır olana kadar dosyayı oku
while ((satir = br.readLine()) != null) {
System.out.println(satir);
// satirlari bosluklara gore bol
StringTokenizer st = new StringTokenizer(satir);

while (st.hasMoreElements()) {
for (int i = 0; i<3; i++) {
dizi[j][i] = st.nextElement().toString();
}
j++;

}
}

// kaynak dugumler
for (int k = 0; k< 8; k++) {
System.out.println(dizi[k][0]);

}

} catch (IOException e) {
e.printStackTrace();
}

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

}
}

graph.txt

a b 5
a c 4
b c 4
b f 6
c d 3
c f 5
d e 3
f e 2

« »