I'm using FileWriter to write to a folder in a Unix environment but when I deploy and run I receive an error saying no such file or directory.
The same code works in the window environment I tested in. is there some special format I need to be using? The directory I'm trying to write to is on the root level and the jar with my code is in another directory about 4 folders deep.
Right now I'm trying :
As Greg mentions, you should not be using a backslash. The correct way is to use the File.separatorChar to determine what the correct separator character is supposed to be - that way you do not have to worry about what operating system you are going to deploy on.
Most Unix environments do not have a /temp directory, however most of them have a /tmp directory. However even this knowledge will not help you if you end up deploying to some other operating system in the future. Once again, the creators of Java thought about these issues, and they provided a File.createTempFile(String prefix, String suffix) that will do the hard work of determining a good location for the temporary file for you.
File.separator on Unix is going to contain "/" anyway, so if it didn't work with explicit slashes, it's not going to work by concatenating in File.separator. There must be some other issue there. It could be permissions, which can be trickier on Unix. That directory (../temp, ../tmp, or /tmp I'm not sure which one you settled on) must exist. If test.log exists, it must be writable for your user. If not, then the directory must be writable to create it. I think the directory would have to be executable in either case.
As a side point, there's no need to ever use File.separator since "/" in Java paths works on every platform, including Windows. You can safely ignore this particular detail of Windows' backwardness.
Joined: Aug 12, 2004
i have the proper permissions when executing the jar. maybe it's a matter of the number of "."'s since I'm calling the class from 4 directories down and the location i want to write to is closer to the root. I've only tried with 2 dots ie
author and jackaroo
In writing that, I realized another potential issue as well - you keep talking about the location of your deployed Jar file, when you should really be talking about the current working directory (or, at least, if you want to keep using relative paths to get to a known absolute path, then the relative path should be relative to your current working directory).