Added MazeReadingException class

This commit is contained in:
antograb authored and antograb committed 2017-11-25 08:50:22 +01:00
1 parent cc3d30e74f
commit dbf4ea3ab5
7 files changed
+141

No files matched your search

+34
View File
@@ -1,3 +1,5 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
public class Maze
@@ -46,6 +48,38 @@ public class Maze
return vertexList ;
}
public final void initFromTextFile(String filename) {
FileReader fr = null ;
BufferedReader br = null ;
try {
fr = new FileReader(filename) ;
br = new BufferedReader(fr) ;
int lineLength = br.readLine().length() - 1 ;
int currentLineLength ;
int cInt = br.read() ;
while (cInt != -1)
{
currentLineLength = br.readLine().length() ;
if (currentLineLength != lineLength) {
throw new MazeReadingException(filename) ;
}
cInt = br.read() ;
}
} catch (MazeReadingException mre) {
mre.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try { br.close() ;} catch (Exception e) {}
}
}
public int getDimensionX() {
return dimensionX;
}