title: Check if URL exists or not on Server
body: <p>This is my code which I am using to verify, URL exists or not on Server, but always getting not exist however link is alive</p>
  
  <p>Where I am doing mistake in my code, why I am always getting <em>"doesnot exist !"</em></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);     
  
          String customURL = "http://www.desicomments.com/dc3/08/273858/273858.jpg";
          boolean bResponse = exists(customURL);
  
          if (bResponse==true)
          {
              Toast.makeText(MainActivity.this, "File exists!", Toast.LENGTH_SHORT).show();      
          }
          else
          {           
              Toast.makeText(MainActivity.this, "File does not exist!", Toast.LENGTH_SHORT).show();
          }   
  
      }
  
      public static boolean exists(String URLName){
          try {
              HttpURLConnection.setFollowRedirects(false);
              HttpURLConnection con =  (HttpURLConnection) new URL(URLName).openConnection();
              con.setRequestMethod("HEAD");
              return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
          }
          catch (Exception e) {
              e.printStackTrace();
              return false;
          }
      }
  
  }
  </code></pre>