Aleksandar Zoric Aleksandar Zoric - 1 month ago 31
Java Question

Java - Invalid File path

My application throws exception - java.io.FileNotFoundException: Invalid file path. Not sure why. 'message' variable is a string that contains the name of my sub folder, which is inside 'ServerFolder'.

writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("C:\\ServerFolder\\" + message + "\\" + " " + todaysDate + ".txt"), "utf-8"));

Answer

Instantiation of FileOutputStream is throwing the FileNotFoundException. Ensure that the path that you are passing in the String to FileOutputStream constructor is valid and you have permissions to create files in the directory.