#Create a file from Resource
14 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @forest hill! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
what happens when trying?
Nothing, it just don't work
and what did you try?
I found a way and it loaded the file but in the wrong way and snakeyaml didn'd return any data
?
I tried this
if (resourcePath != null && !resourcePath.equals("")) {
resourcePath = resourcePath.replace('\\', '/');
InputStream in = this.getResource(resourcePath);
if (in == null) {
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + configFile.getName());
}
File outFile = new File(configFile, resourcePath);
int lastIndex = resourcePath.lastIndexOf(47);
File outDir = new File(configFile, resourcePath.substring(0, Math.max(lastIndex, 0)));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (outFile.exists() && !replace) {
Logger.getLogger("FadedMusicBot").log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
} else {
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
} catch (IOException var10) {
Logger.getLogger("FadedMusicBot").log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, var10);
}
} else {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}
}```
configFile = new File(getProgramPath() + File.separator + directory.replace("/", File.separator));
if (!configFile.exists()) {
configFile.getParentFile().mkdirs();
saveResource(directory, replace);
}
yaml.load(directory);
}```
and it created a folder called config.yml containing the actual .yml file and snakeyaml doesn't return any data from it
what is the yaml variable?