File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Downloading a Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Downloading a Directory" Watch "Downloading a Directory" New topic
Author

Downloading a Directory

Sumit Israni
Greenhorn

Joined: Jun 20, 2001
Posts: 28
Hi All,
Could anyone please help me resolve this problem :I want to download an entire directory .I am using the com.oreilly.servlet package .I am utilizing the ServletUtils class in it.Following is the code in it which I want to modify in order to download an entire directory/folder.Of course in the returnFile() method I am passing a Directory name rather than just a file name.
<code>
File f1=new File(dirname);
String s[]=f1.list();
int i;
for (i=0;i<s.length;i++)
{
byte[] buf=new byte[4 * 1024];
buf=s[i].getBytes();
out.write(buf);

}
</code>
I am getting a bit stuck in the above code as to how to output an array of bytes(the array contains the filenames in the directory as obtained by the list() method.) to the output stream.
Any help will be much appreciated.Thanks a lot.


ben rowe
Greenhorn

Joined: Aug 16, 2001
Posts: 5
I got the following code to work:
for (int i=0;i<s.length;i++)
{
out.println(s[i]);
}
I'm assuming out is ServletOutputStream and since that is a character writer I don't know why you think you have to be working with bytes.

[This message has been edited by ben rowe (edited September 03, 2001).]
[This message has been edited by ben rowe (edited September 03, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Downloading a Directory
 
Similar Threads
How to get byte of arralylist
How to transfer variable values from one servlet to another?
Directory Download Servlet(Need your help asap!)
To Save a file in a different location
File Download problem using icefaces