Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading and Writing Files In Ejb

 
Pankaj Narang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

-Ram
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic