Hey everyone! so i was creating a file during runt...
# stdlib
a
Hey everyone! so i was creating a file during runtime and then accessing it (File.readLines()) but it throws an error of file not found? Is it because we cannot read the file created during runtime? If so is there any work around happy to discuss
b
Did you actually write the file? Just constructing File instance does not create a file
Also this is not really kotlin specific
a
so right now what happens is there is a ProcessBuilder which creates a file at runtime and i just need to read some outputs of those file
i too feel its not kotlin specific but when i hardcode the file path it reads it
b
Might be a race condition then. Check if the file exists before accessing it via File::exists
Also check your file's canonicalPath to verify that it's pointing to where you expect
a
i even tried making Thread.sleep for a few sec but no outcome. File::exists show that this file does not exists but it does.
I’ll check once with the canonicalpath
b
Most likely paths are resolving differently to what you expect
This is likely due to processed running in different workingDirs and using relative paths
👍 1
To be honest this smells like bad architecture
Easiest fix, convert file to absolute file before writing and passing it along
a
Great! altho i switched the working dirs to the project root. That solved my problem
e
this sounds like gradle, in which case 1. you cannot rely on a particular working directory within the build script, it depends on how Gradle was launched 2. you should use
exec {}
or an
Exec
task instead of
ProcessBuilder
3. 😶