If I continue out of this try catch would the stream be closed? for(Chunk chunk : world)…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
If I continue out of this try catch would the stream be closed?
for(Chunk chunk : world) { // Store chunks in sections to better distribute data int xSection = (int) Math.floor(chunk.getChunkX() / ResourceReader.CHUNKS_PER_FILE); int ySection = (int) Math.floor(chunk.getChunkY() / ResourceReader.CHUNKS_PER_FILE); int zSection = (int) Math.floor(chunk.getChunkZ() / ResourceReader.CHUNKS_PER_FILE);
code// ~~Append needs to be true for multiple chunks!!!!!!!~~ // but i think were gonna do one chunk per file because file sizes are unpredictable try(RandomAccessFile output = new RandomAccessFile(chunkFolder.getAbsolutePath() + "/" + xSection + " " + ySection + " " + zSection, "rw")) { // Placeholder for the number of bytes needed for this chunk // A 0 indicates the chunk is empty output.writeByte(0); // If the chunk is empty if(chunk.isEmpty()) { continue; }AND if on another chunk loop would the new chunk data be appended to the end of the file with RandomAccessFile?
- Assistant
Let's dissect your questions step by step:
-
Would the stream be closed if you continue out of this try-catch?
Yes, the stream will be closed. This is because you are using a try-with-resources statement (), which automatically closes any resources that implement the interface (like ) when the try block exits, regardless of the way it exits (whether it’s via normal completion or an exception).
-