mrkirby153

Untitled

Oct 7th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. String contents = "";
  2.         File file = new File("textfile.txt");
  3.         if(!file.exists()){
  4.             try {
  5.                 System.out.println("Creating");
  6.                 file.createNewFile();
  7.                 System.out.println("Created");
  8.             } catch (IOException e) {
  9.                 // TODO Auto-generated catch block
  10.                 e.printStackTrace();
  11.             }
  12.  
  13.         }
  14.         try{
  15.  
  16.             BufferedReader br = new BufferedReader(new FileReader("hut.house"));
  17.             String strLine;
  18.             //Read File Line By Line
  19.             while ((strLine = br.readLine()) != null)   {
  20.                 // Print the content on the console
  21.                 contents += strLine;
  22.             }
  23.             //Close the input stream
  24.             br.close();
  25.             System.out.println(contents);
  26.         }catch (Exception e){//Catch exception if any
  27.             System.err.println("Error: " + e.getMessage());
  28.         }
  29.         System.out.println("Splitting");
  30.         // Split into coordinate "chunks"
  31.         String[] split = contents.split(";");
  32.         for(int i=0; i < split.length; i++){
  33.             // Split into x, y, z, id+meta
  34.             String[] split1 = split[i].split(":");
  35.             System.out.println("--------");
  36.             String id = split1[3];
  37.             // Split into id, meta
  38.             String[] split2 = split1[3].split(",");
  39.             int x = Integer.parseInt(split1[0]);
  40.             int y = Integer.parseInt(split1[1]);
  41.             int z = Integer.parseInt(split1[2]);
  42.             int block_id = 0;
  43.             if(id.substring(0, id.length()-2).equals("X")){
  44.                 block_id = 35;
  45.             }else{
  46.                 block_id = Integer.parseInt(id.substring(0, id.length()-2));
  47.             }
  48.             int block_meta = Integer.parseInt(split2[1]);
  49.             System.out.println("Coords: "+x+" "+y+" "+z+" "+" Block: "+block_id+":"+block_meta);
  50.         }
  51.  
  52.  
  53. turns
  54. 0:0:0:1,0;1:0:0:2,0;2:0:0:3,0;3:0:0:3,0;0:0:10:X,0;
  55.  
  56. into
  57.  
  58. Creating
  59. Created
  60. 0:0:0:1,0;1:0:0:2,0;2:0:0:3,0;3:0:0:3,0;0:0:10:X,0;
  61. Splitting
  62. --------
  63. Coords: 0 0 0  Block: 1:0
  64. --------
  65. Coords: 1 0 0  Block: 2:0
  66. --------
  67. Coords: 2 0 0  Block: 3:0
  68. --------
  69. Coords: 3 0 0  Block: 3:0
  70. --------
  71. Coords: 0 0 10  Block: 35:0
Advertisement
Add Comment
Please, Sign In to add comment