Dear all, Because an enterprise bean cannot must not use java.io package to access file and directories in the file system. How does an enterprise bean access files or directories in the file system? thanks daniel
It depends on what you are trying to do. I am all in favor of breaking the no java.io.* rule in some cases. For example, I see no problem in accessing the file system to get a complex configuration file and in some cases it can't be easily avoided (ie. third-party libraries that use config files). However, I would definitely recommend staying away from any read-write file IO.
Why should you not use java.io.* in EJB's? For instance, I have a MessageDrivenBean which does some image processing. In my JMS message to the bean I include the absolute path to the image file. Then I do the processing, and save the image. Is there anything wrong with that? (I'm asking because I have to use the java.io.File class).
And in my specific case? Because i'm violating the spec, can I break something?
Joined: Jan 23, 2002
You can break the spec but in your case, I would implement the file/image processing stuff in such a way that a possible rollback of a transaction would not mess things up (for example, use a temp file that won't affect your program even if it is left hanging around for some reason).
One nice trick is to bind part of the filesystem in via JNDI and access files on the filesystem that way. With JBoss this is pretty straightforward. It might be harder to do in other app servers. (and as such really couldn't be considered a portable technique)