diff --git a/core/src/main/java/cc/carm/lib/configuration/core/source/impl/FileConfigProvider.java b/core/src/main/java/cc/carm/lib/configuration/core/source/impl/FileConfigProvider.java index 46bacb6..ffffd13 100644 --- a/core/src/main/java/cc/carm/lib/configuration/core/source/impl/FileConfigProvider.java +++ b/core/src/main/java/cc/carm/lib/configuration/core/source/impl/FileConfigProvider.java @@ -49,16 +49,15 @@ public void initializeFile(@Nullable String sourcePath) throws IOException { public void saveResource(@NotNull String resourcePath, boolean replace) throws IOException, IllegalArgumentException { Objects.requireNonNull(resourcePath, "ResourcePath cannot be null"); - if (resourcePath.equals("")) throw new IllegalArgumentException("ResourcePath cannot be empty"); + if (resourcePath.isEmpty()) throw new IllegalArgumentException("ResourcePath cannot be empty"); resourcePath = resourcePath.replace('\\', '/'); URL url = this.getClass().getClassLoader().getResource(resourcePath); if (url == null) throw new IllegalArgumentException("The resource '" + resourcePath + "' not exists"); - int lastIndex = resourcePath.lastIndexOf('/'); - File outDir = new File(file.getParentFile(), resourcePath.substring(0, Math.max(lastIndex, 0))); - + File outDir = file.getParentFile(); + if (!outDir.exists() && !outDir.mkdirs()) throw new IOException("Failed to create directory " + outDir); if (!file.exists() || replace) { try (OutputStream out = Files.newOutputStream(file.toPath())) {