mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
fix(init): 尝试修复初始化创建无用文件的问题 #40
This commit is contained in:
+2
-3
@@ -49,15 +49,14 @@ public abstract class FileConfigProvider<W extends ConfigurationWrapper<?>> exte
|
|||||||
public void saveResource(@NotNull String resourcePath, boolean replace)
|
public void saveResource(@NotNull String resourcePath, boolean replace)
|
||||||
throws IOException, IllegalArgumentException {
|
throws IOException, IllegalArgumentException {
|
||||||
Objects.requireNonNull(resourcePath, "ResourcePath cannot be null");
|
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('\\', '/');
|
resourcePath = resourcePath.replace('\\', '/');
|
||||||
|
|
||||||
URL url = this.getClass().getClassLoader().getResource(resourcePath);
|
URL url = this.getClass().getClassLoader().getResource(resourcePath);
|
||||||
if (url == null) throw new IllegalArgumentException("The resource '" + resourcePath + "' not exists");
|
if (url == null) throw new IllegalArgumentException("The resource '" + resourcePath + "' not exists");
|
||||||
|
|
||||||
int lastIndex = resourcePath.lastIndexOf('/');
|
File outDir = file.getParentFile();
|
||||||
File outDir = new File(file.getParentFile(), resourcePath.substring(0, Math.max(lastIndex, 0)));
|
|
||||||
|
|
||||||
if (!outDir.exists() && !outDir.mkdirs()) throw new IOException("Failed to create directory " + outDir);
|
if (!outDir.exists() && !outDir.mkdirs()) throw new IOException("Failed to create directory " + outDir);
|
||||||
if (!file.exists() || replace) {
|
if (!file.exists() || replace) {
|
||||||
|
|||||||
Reference in New Issue
Block a user