I've created a world that I have stored on a file on my labtop, but having a difficult time of reading that file in Greenfoot. I want this to appear in the world. Does anybody know how to do this?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | public String[] readText() throws IOException { InputStream is = getClass().getClassLoader().getResourceAsStream( "pars.txt" ); BufferedReader r = new BufferedReader( new InputStreamReader(is)); String[] lines = new String[maxLevel- 1 ]; for ( int i = 0 ; i < maxLevel- 1 ; i++) { lines[i] = r.readLine(); } return lines; } public String readText( int row) throws IOException { InputStream is = getClass().getClassLoader().getResourceAsStream( "pars.txt" ); BufferedReader r = new BufferedReader( new InputStreamReader(is)); String[] lines = new String[maxLevel- 1 ]; for ( int i = 0 ; i < maxLevel- 1 ; i++) { lines[i] = r.readLine(); } return lines[row]; } |
1 2 3 4 5 6 7 8 | try { readText( 3 ); } catch (IOException iox) { //What to do if it fails to read text } |