cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ray Martin" <raymar...@aci-hq.com>
Subject RE: How do I read files inside an Action?
Date Wed, 18 Dec 2002 19:42:38 GMT
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:schintalapaty@ptc.com]
> Sent: Wednesday, December 18, 2002 10:00 AM
> To: cocoon-users@xml.apache.org
> 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:     <cocoon-users-unsubscribe@xml.apache.org>
> For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>
>
>



---------------------------------------------------------------------
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:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message