From bc67de06f62ade75e226002c7d490bf76f88aa40 Mon Sep 17 00:00:00 2001 From: carm Date: Thu, 10 Aug 2023 01:57:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(init):=20=E5=B0=9D=E8=AF=95=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96=E5=88=9B=E5=BB=BA=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98=20#40?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/core/source/impl/FileConfigProvider.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 abstract class FileConfigProvider> exte 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())) {