Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: Getting the Content Type
02-01-2008, 08:38 PM #1
Getting the Content Type
Does anyone know of any utilities that can give you the http content type of a file based on its extension? I couldn't find anything in the javadocs and google hasn't been very much help for me so far.
What I'm looking to do is take a file, for example a pdf file: myfile.pdf. Look at the extension and know to set the content type on the http response to "application/pdf" or "application/msword" for word docs etc....
I can do this, but I cannot find a way to do it dynamically without writing an individual case for any document type I want to support. That just seems like an ugly way to handle it.
02-01-2008, 10:09 PM #2
- Join Date
- Jan 2008
- Willow Grove, PA
- Thanked 27 Times in 27 Posts
You could write a properties file and have the Properties class load that file.
Code:String contentType = props.getProperty(fileExrtension);
02-02-2008, 01:38 PM #3
That is the direction I was leaning towards, but I was hoping to get out of it. This is a really simple program and was hoping to leave out any complexity that I could. Thanks for the reply, that solution will work great.