Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6133165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:11:36+00:00 2026-05-23T17:11:36+00:00

I can get all those url’s whose content/type is text/html, but If I want

  • 0

I can get all those url’s whose content/type is text/html, but If I want those urls whose content/type is not text/html. Then how can we check that. As for the string we can use contains method, but it doesn’t have anything like notcontains.. Any suggestions will be appreciated.. And also

The key variable contains:

Content-Type=[text/html; charset=ISO-8859-1]

This is the below code to check for text/html and I tried also for content-type that are not text/html but it also prints out those whose content-type are also text/html.

    try {
            URL url1 = new URL(url);
            System.out.println("URL:- " +url1);
            URLConnection connection = url1.openConnection();

            Map responseMap = connection.getHeaderFields();
            Iterator iterator = responseMap.entrySet().iterator();
            while (iterator.hasNext())
            {
                String key = iterator.next().toString();

                if (key.contains("text/html") || key.contains("text/xhtml"))
                {
                    System.out.println(key);
                    // Content-Type=[text/html; charset=ISO-8859-1]
                    if (filters.matcher(key) != null){
                        System.out.println(url1);
                        try {
                            final File parentDir = new File("crawl_html");
                            parentDir.mkdir();
                            final String hash = MD5Util.md5Hex(url1.toString());
                            final String fileName = hash + ".txt";
                            final File file = new File(parentDir, fileName);
                            boolean success =file.createNewFile(); // Creates file crawl_html/abc.txt


                             System.out.println("hash:-"  + hash);

                                    System.out.println(file);
                            // Create file if it does not exist



                                // File did not exist and was created
                                FileOutputStream fos = new FileOutputStream(file, true);

                                PrintWriter out = new PrintWriter(fos);

                                // Also could be written as follows on one line
                                // Printwriter out = new PrintWriter(new FileWriter(args[0]));

                                            // Write text to file
                                Tika t = new Tika();
                                String content= t.parseToString(new URL(url1.toString()));


                                out.println("===============================================================");
                                out.println(url1);
                                out.println(key);
                                out.println(success);
                                out.println(content);

                                out.println("===============================================================");
                                out.close();
                                fos.flush();
                                fos.close();



                        } catch (FileNotFoundException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block

                            e.printStackTrace();
                        } catch (TikaException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }


                        // http://google.com
                    }
                }
  else if (!connection.getContentType().startsWith("text/html"))//print duplicate records of each url
                //else if (!key.contains("text/html"))
                {
                    if (filters.matcher(key) != null){
                     try {
                        final File parentDir = new File("crawl_media");
                        parentDir.mkdir();
                        final String hash = MD5Util.md5Hex(url1.toString());
                        final String fileName = hash + ".txt";
                        final File file = new File(parentDir, fileName);
                     // Create file if it does not exist
                        boolean success =file.createNewFile(); // Creates file crawl_html/abc.txt


                         System.out.println("hash:-"  + hash);

                         Tika t = new Tika();
                        String content_media= t.parseToString(new URL(url1.toString()));



                             // File did not exist and was created
                            FileOutputStream fos = new FileOutputStream(file, true);

                             PrintWriter out = new PrintWriter(fos);

                             // Also could be written as follows on one line
                             // Printwriter out = new PrintWriter(new FileWriter(args[0]));

                                         // Write text to file
                             out.println("===============================================================");
                             out.println(url1);
                             out.println(key);
                             out.println(success);
                             out.println(content_media);
                             //out.println("===============================================================");
                             out.close();
                             fos.flush();
                             fos.close();




                     } catch (FileNotFoundException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
                     } catch (IOException e) {
                         // TODO Auto-generated catch block

                         e.printStackTrace();
                     } catch (TikaException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    }

                }



            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }



        System.out.println("=============");
    }   
}

One method is to check individually for each content-type like for pdf it is application/pdf

if (key.contains("application/pdf")

and in the same way for xml… But any other method other than this…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:11:36+00:00Added an answer on May 23, 2026 at 5:11 pm

    Would this help?

     if (!connection.getContentType.startsWith("text/html"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please tell me how can I get array of all Those DIV of specific
Can get all triples with value null in specific field? All people with date_of_birth
I have a function that I can get all the correct values for with
Is there any API by which one can get all the categories of a
I am wondering how I can get all the files with File Info and
I am trying to write DOM viewer on JavaScript. How I can get all
Can i get all the events and other informations from android device default calendar
How can I get all items from a specific calendar (for a specific date).
How can i get all the users from the LDAP using PHP. function getUsers()
How can I get all products from customers1 and customers2 include their customer names?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.