Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I read multiple files in one directory from URL?

 
Alan Blass
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I have multiple files in a directory and I want to send it as an email attachment:

Eg:

http://www.mysite.com/myDirectory/

contains file1.txt, file2.txt.

I know how to attach it in an email. I just don't know how to read the files from the directory and pass it into:

URL url = new URL("http://www.mysite.com/myDirectory/");

File file = new File(url);

Please help. Thanks.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would likely not use a File, but work with an InputStream - which you can get via url.openStream().
 
Alan Blass
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Thanks for your reply.

Is it possible to list the files in that directory?Because the filenames in that directory is unknown.

Thanks.
 
Paul Clapham
Sheriff
Posts: 21142
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "that directory". What you showed us so far is an HTTP URL, and those can't be used to represent a directory.
 
Robert D. Smith
Ranch Hand
Posts: 212
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if what you want can be done. But I would start with the URLConnection class.

Regards,
Robert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic