-
- InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename);
- if (in == null)
- continue; // Try the next name: no such file found
-
- OutputStream out = null;
- try {
- // We must write the lib onto the disk before loading it -- stupid operating systems
- if (tempDir == null) {
- tempDir = Files.createTempDirectory("simgrid-java-");
- // don't leak the files on disk, but remove it on JVM shutdown
- Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(tempDir.toFile())));
- }
- File fileOut = new File(tempDir.toFile().getAbsolutePath() + File.separator + filename);
+
+ File fileOut = new File(tempDir.toFile().getAbsolutePath() + File.separator + filename);
+ try ( // Try-with-resources. These stream will be autoclosed when needed.
+ InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(path+filename);
+ OutputStream out = new FileOutputStream(fileOut);
+ ) {
+ if (in == null)
+ continue; // Try the next name: no such file found