mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2024-09-19 20:25:51 +00:00
fix(init): 尝试修复初始化创建无用文件的问题 #40
This commit is contained in:
parent
b668794f5d
commit
bc67de06f6
@ -49,15 +49,14 @@ public abstract class FileConfigProvider<W extends ConfigurationWrapper<?>> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user