File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Reading and Writing Files In Ejb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Reading and Writing Files In Ejb" Watch "Reading and Writing Files In Ejb" New topic

Reading and Writing Files In Ejb

Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi ALL
Can we read/write a file from/to a shared directory (can be on local
machine or remote machine) from an EJB

If yes How to do this, any supported link ,tutorials?

Thanks in advnace

Pankaj Narang
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Not directly - the EJB spec. doesn't allow direct IO. There are good reasons for this: an EJB can't make any assumptions about what kind of file system its on, whether the application server has any access right to the file system, where the file resides in a clustered environment, or if there is even a file system at all (e.g. its deployed in something like JServer). Its also difficult to control file access security. And File IO isn't transactional, isn't best fit for enterprise systems.

You can however access the file system through a JCA adapter. This will sort the problems with file access, and you'll find JCA adapters for file system resources in some Application Servers already.

Another alternative is to use an RDBMS like a file system - and store/retrieve files as BLOBS. A lot of DBAs might be horrified by that suggestion, but it is a quick convenient way round this issue.
[ July 29, 2004: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I hv got the same problem....I got to access the file system from EJB running under Websphere 5.0.2.

As mentioned in the above can anybody advise me how can I use JCA adaptor in Websphere 5.0.2 as I dont find any such adaptor in it to access file system.

Any suggestion or idea or alternative most welcome.

Thank you for your time.

I agree. Here's the link:
subject: Reading and Writing Files In Ejb
It's not a secret anymore!