Results 1 to 3 of 3
  1. #1
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default Content type for MS files "content/unknown" with URLConnection

    Hi everybody,

    I need to get content type of the files when I connect to to FTP server (with the help of apache library). The connection to FTP is ok, the content type for files can be known with URLConnection, but when I want to get Content type from MS files on the FTP server, I get "content/unknown". I tried to user guessContentTypeFromName() and guessContentTypeFromStream() methods, I get null value. Eranga I think you have read a book about Netwroking, give me some tips, this is my method:

    Java Code:
     public String getContentType(URL connectionURL) {
            try {
                URLConnection conn = connectionURL.openConnection();
                contentType = conn.getContentType();
            } catch (IOException e) {
                if (log.isDebugEnabled())
                    log.debug("Content type is null");
            }
            return findContentType(connectionURL.getFile());
    findContentType(con.getFile())- this method returns content by finding the extension of the file, but that is not what i want, cuz I need to parse a document with the proper parser for the file.
    }
    Last edited by serjant; 05-29-2009 at 03:04 PM.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    804
    Rep Power
    6

    Default

    Hi Serjant,
    I'm not that familiar with networking.But,I have gone thru this URLConnection class source.Might be headerfield "content-type" is null I think.Please check it once.
    Ramya:cool:

  3. #3
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Thanks for the help, I have got another idea how to do that , I wrote some filter which will recognize the extensions of the files which are downloaded from the server, which will give the content type in to the headers when they are in the stream, and then I can easily parse them. Solved

Similar Threads

  1. Replies: 1
    Last Post: 05-20-2009, 08:46 PM
  2. Hi , Error in Jsp page is as "NumberFormatException.forInputString(Unknown Source)"
    By lavanya82 in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 02-20-2009, 07:22 AM
  3. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. Getting content type from a website
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-26-2007, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •