Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String contents = "";
- File file = new File("textfile.txt");
- if(!file.exists()){
- try {
- System.out.println("Creating");
- file.createNewFile();
- System.out.println("Created");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- try{
- BufferedReader br = new BufferedReader(new FileReader("hut.house"));
- String strLine;
- //Read File Line By Line
- while ((strLine = br.readLine()) != null) {
- // Print the content on the console
- contents += strLine;
- }
- //Close the input stream
- br.close();
- System.out.println(contents);
- }catch (Exception e){//Catch exception if any
- System.err.println("Error: " + e.getMessage());
- }
- System.out.println("Splitting");
- // Split into coordinate "chunks"
- String[] split = contents.split(";");
- for(int i=0; i < split.length; i++){
- // Split into x, y, z, id+meta
- String[] split1 = split[i].split(":");
- System.out.println("--------");
- String id = split1[3];
- // Split into id, meta
- String[] split2 = split1[3].split(",");
- int x = Integer.parseInt(split1[0]);
- int y = Integer.parseInt(split1[1]);
- int z = Integer.parseInt(split1[2]);
- int block_id = 0;
- if(id.substring(0, id.length()-2).equals("X")){
- block_id = 35;
- }else{
- block_id = Integer.parseInt(id.substring(0, id.length()-2));
- }
- int block_meta = Integer.parseInt(split2[1]);
- System.out.println("Coords: "+x+" "+y+" "+z+" "+" Block: "+block_id+":"+block_meta);
- }
- turns
- 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;
- into
- Creating
- Created
- 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;
- Splitting
- --------
- Coords: 0 0 0 Block: 1:0
- --------
- Coords: 1 0 0 Block: 2:0
- --------
- Coords: 2 0 0 Block: 3:0
- --------
- Coords: 3 0 0 Block: 3:0
- --------
- Coords: 0 0 10 Block: 35:0
Advertisement
Add Comment
Please, Sign In to add comment