How do I perform I/O operations from a bean?

Richard Monson-Haefel

Using is prohibited

Using the package from within a bean is prohibited. The EJB 1.1 Specification, section 18.1.2 (Programming Restrictions) states the following:
  • An enterprise bean must not use the package to attempt to access files and directories in the file system.

    The file system APIs are not well-suited for business components to access data. Business components should use a resource manager API, such as JDBC API, to store data.

  • The EJB 1.1 specification is available for download from

    Alternative Solutions

    To perform I/O operations you must use a resource connection supported by the EJB programming model. EJB servers may support several resource connection options, which can be used to log events as shown below:
    • JDBC (javax.sql.DataSource) : Write I/O data in to a relational database.
    • URL ( : Write I/O data to a custom server or post them to a web server.
    • JavaMail (javax.mail.Session) : E-mail I/O data to a special account
    • JMS (javax.jms.QueueConnectionFactory | javax.jms.TopicConnectionFactory) : Send the I/O data as messages.
    Comment and Contribute






    (Maximum characters: 1200). You have 1200 characters left.