The code should check if there is a file created named ciclos.txt and then, if there isnt, create the file. If there is one then should say that its already created. I tried multiple options but no matter what always getting the same result, with or without file created.
Any ideas whats happening? (Something silly probably)
#createNewFile() conditional always being false
18 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @unborn plover! 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.
You forgot to do a thing
"if file does not exist, create it"
Also don't name variables with Pascal_Case
that's not what you do in Java
variables are either CAPS_SNAKE_CASE if static final or standardCamelCase if other
Why are you using colons( :)?
Also, I suggest using Path class as it allows better control
Path filePath = Paths.get("location", "location2", "file");
and then you can either do File pathFile = filePath.toFile() and do the Boolean checks, or just use raw calls like
if (!filePath.toFile().exists()) {
}```
Usually you do the exists call before making new file as you don't want to create a new file every time, no matter the case of whether or not the file exists or not
you want to only make the file when it doesn't exist
Here's an example of mine that I use in prod:
Path getConfigFilePath() throws IOException {
var configFilePath = Paths.get(String.valueOf(LauncherUtils.WORKING_DIR_PATH),
MessageFormat.format("{0}_{1}.properties",
"twentyten", System.getProperty("user.name")));
var configFile = configFilePath.toFile();
if (!configFile.exists() && !configFile.createNewFile()) {
throw new IOException();
}
return configFilePath;
}
I should probably change the double condition to return null instead with a warning
Thanks, I managed to figure out with your answers :)
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.