File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Downloading a Directory

 
Sumit Israni
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic