Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

content-disposition & URLconnection  RSS feed

justin wall
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Here is some of the code:
readMe = new URL("" + i);
URLConnection rc = readMe.openConnection();
System.out.println("filename: " + rc.getHeaderField("Content-Disposition"));

BufferedReader in = new BufferedReader(
new InputStreamReader(

// Create the stream for the output file
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter(
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!