我试图通过从文件中获取以下坐标并通过将这些坐标放入ArrayList然后从int 0开始并找到它连接并转到1来找到从0到1的路径来解决难题。
11 3
2 3
0 3
1 4
5 4
5 7
6 7
7 8
8 9
9 10
0 5
到目前为止,我已经完成了从文件中获取值并将其放入ArrayList,
ArrayList<String[]> listValues = new ArrayList<String[]>();
ArrayList<String> resultSet= new ArrayList<String>();
try{
String line = null;
String fileName =("C:\\Users\\Kamran Ali\\Documents\\NetBeansProjects\\TestMazeDone\\maze1.txt");
System.out.println("File: " +fileName);
BufferedReader br = new BufferedReader(new FileReader(fileName));
while ((line = br.readLine())!= null)
{
String[] locations = line.split(" ");
listValues.add(locations);
}
br.close();
}
//Handling File not found or Path Error Exceptions
catch(FileNotFoundException ex){
System.out.println("Specified file does'nt exist");
}
//Handling Input/Output Exceptions
catch(IOException ex){
System.out.println("There was an error, please try again");
}
我没有任何线索如何做其余的事,这是:
上述文件的输出应如下所示:
[0 5 4 1]