try (FileInputStream fs = new FileInputStream(dir + "sample.rar")) { try (RarArchive archive = new RarArchive(fs)) { // The extract method extracts the entry to the filesystem by the path provided. archive.getEntries().get(0).extract(dir + "sample-1_1.webp"); } } catch (IOException e) { e.printStackTrace(); }