0

I've been trying to get the MIME type of a file and then check if the file is one of css, but it doesn't seem to be working. The snippet is:

String fileName = '/'+uri.getPath().substring(PATH.length());
URLConnection inputURL = getClass().getResource(fileName).openConnection();
InputStream inputStream = null;
try {
    inputURL.setUseCaches(false);
    inputStream = inputURL.getInputStream();
    String mimeType = inputURL.getContentType();
    if (inputStream != null) {
        if (mimeType.equals("text/css")) {...}
                    else{...}...
Sam
  • 405
  • 2
  • 5
  • 13
  • 2
    For better help sooner, post an [SSCCE](http://pscode.org/sscce.html). BTW, I doubt `getContentType()` would work off the local file system. And ..what is your question? – Andrew Thompson Jul 17 '11 at 14:36
  • 2
    What isn't working? What's the observed vs. expected behavior? – g051051 Jul 17 '11 at 14:36

1 Answers1

0

I think that content type will be filled if you perform HTTP connection, e.g.

URLConnection c = new URL("http://foo/bar").openConnection();
String mimeType = c.getContentType();

In this case the content type is sent over HTTP as a header and is parsed by appropriate protocol handler. I think that this property is not initialized at all when getting so called URLConnection from resource.

AlexR
  • 114,158
  • 16
  • 130
  • 208