I was woundering if anyone knows the proper way to right to a file outside the webcontainer. for exampl i have a Java servlet / JSP applicaton that the user can upload files. the files are going to be served via Apache but I wanna make sure that i'm staying to spec with J2EE. My current solution is to just synchronize the code block of both the fileoutputstream and the unique file name generator. Any suggestions?
If you are always generating a new file name, there is no need to synchronize the I/O operations, because the I/O will never touch the same file. Just synchronizing the file-name generator should be enough.
If you allow the application to update (overwrite) existing files, you will need some sort of file locking mechanism for true thread-safety.