Skip to content

Commit

Permalink
fix(init): 尝试修复初始化创建无用文件的问题 #40
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Aug 9, 2023
1 parent b668794 commit bc67de0
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down

0 comments on commit bc67de0

Please sign in to comment.