I am trying to write a file to a directory without setting an absolute path. I have multi-project build in Intellij and I have a separate directory for files:
-Intellij project
---project-1
---project-2
---project-3
---test-files
And I want to write a file to the files directory without defining an absolute path because I am going to run it on the cluster, where I do not know build path. However, I was able only to reach the root project directory. How can I save files to test-files folder?
Here is the code I use. It saved the file to simply project-1 directory:
val directory = new File("./").getCanonicalPath
import java.io.PrintWriter
val printWriter = new PrintWriter(s"$directory/file.txt")
printWriter.write("This is my string")
printWriter.close()
Try specifying parent directory ..
like so
val directory = new File("../test-files")