Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes How do I read multiple files in one directory from URL? 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 » Java in General
Bookmark "How do I read multiple files in one directory from URL?" Watch "How do I read multiple files in one directory from URL?" New topic
Author

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

Alan Blass
Ranch Hand

Joined: Mar 21, 2010
Posts: 119
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
Marshal

Joined: Mar 22, 2005
Posts: 41034
    
  43
You would likely not use a File, but work with an InputStream - which you can get via url.openStream().


Ping & DNS - my free Android networking tools app
Alan Blass
Ranch Hand

Joined: Mar 21, 2010
Posts: 119
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 04, 2013
Posts: 143
    
    5
I'm not sure if what you want can be done. But I would start with the URLConnection class.

Regards,
Robert


There are worse crimes than burning books. One of them is not reading them. Ray Bradbury
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I read multiple files in one directory from URL?
 
Similar Threads
Create File object from URL. How?
Tomcat security constraint doesn't work behind Apache
How many sites are on one tomcat
servlet mapping clarification
java.io.NotSerializableException when overwrite the JTable data into .txt file