Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- final String jarPath = URLDecoder.decode(
- this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(),
- "UTF-8"
- );
- final String filePath = System.getProperty("catalina.base")
- + System.getProperty("file.separator")
- + "configurations"
- + System.getProperty("file.separator")
- + "config.properties";
- final File cfgFile = new File(filePath);
- cfgFile.getParentFile().mkdirs();
- cfgFile.createNewFile();
- final JarFile jarFile = new JarFile(new File(jarPath));
- final Enumeration<JarEntry> entries = jarFile.entries();
- while (entries.hasMoreElements()) {
- final JarEntry jarEntry = entries.nextElement();
- if (jarEntry.getName().equals("config.properties")) {
- try (InputStream in = jarFile.getInputStream(jarEntry)) {
- try (OutputStream out = new FileOutputStream(cfgFile)) {
- byte[] buf = new byte[2048];
- for(int bytesRead = in.read(buf); bytesRead != -1; bytesRead = in.read(buf)) {
- out.write(buf, 0, bytesRead);
- }
- out.flush();
- }
- }
- break;
- }
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- throw new RuntimeException(ex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement