This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes content-disposition & URLconnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "content-disposition & URLconnection" Watch "content-disposition & URLconnection" New topic
Author

content-disposition & URLconnection

justin wall
Greenhorn

Joined: Jul 30, 2001
Posts: 8
I'm trying to download a file. I don't know what the filename is because the URL hits a CGI script. How do I get the filename from before it downloads? A browser is able to, so I think it's in the header. I've tried to get the "content-disposition" field from the URLconnection, however it is null.
Thanks,
Justin
Here is some of the code:
readMe = new URL("http://mysite.com/runthis.php?rid=" + i);
URLConnection rc = readMe.openConnection();
System.out.println("filename: " + rc.getHeaderField("Content-Disposition"));

BufferedReader in = new BufferedReader(
new InputStreamReader(
rc.getInputStream()));

// Create the stream for the output file
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter(
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: content-disposition & URLconnection
 
Similar Threads
FTP
downloading with applet from servlet
send file from java app works in browser but not wget or curl?
GET via URLConnection?
Download file from Servlet via Applet