Sir,

Just like any other file called from java.

In the action class you would need:

import java.io.File; // cocoon has some defaults - this could be one of them

//nothing special here, just an example.  however, this directory is where
cocoon places uploaded files by default.  make yours wherever your xml file
is located.
String currentPath = "C:/Program Files/Apache Group/Tomcat
4.1/work/Standalone/localhost/cocoon/cocoon-files/upload-dir/";

// next three lines checks the directory for files and sets pointer to the
first file in the directory (should put some checks around this)(could
iterate through the list)
File fileDir = new File(currentPath);
File[] listOfFiles = fileDir.listFiles();
String filename = listOfFiles[0].toString();

File uploadDir = new File(currentPath);
File theXMLfile = new File(filename);
System.out.println("The director is: " + theResume.getParent());
System.out.println("The file name: " + theResume.getName());
long fileLen = theXMLfile.length();
Long testThis = new Long(fileLen);
int fileLength = testThis.intValue();
FileInputStream fis = new FileInputStream(theResume);
byte[] byteArray = new byte[fileLength];
int cnt = fis.read(byteArray, 0, fileLength);
fis.close();

byteArray now contains the contents of theXMLfile.  this only works for
ASCII files.  i do not have an example at my fingertips for Unicode.


these are snippets from an action that i have performing.  if you need
anything else, holler.

Ray

> -----Original Message-----
> From: Chintalapaty, Sreedhar [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 18, 2002 10:00 AM
> To: [EMAIL PROTECTED]
> Subject: How do I read files inside an Action?
>
>
> Hi,
>
> Can some one point me to an example of how we can access an xml
> file on the file system from a custom Action?
>
> TIA,
>
> Sreedhar
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
> For additional commands, e-mail:   <[EMAIL PROTECTED]>
>
>



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to