LoginSignup
2
1

More than 5 years have passed since last update.

特定のHTMLファイルが存在するか

Last updated at Posted at 2014-11-29
test.java
package test;
import java.net.HttpURLConnection;
import java.net.URL;

public class Test {

    public static void main(String[] args) {
        Test test = new Test();
        test.urlCheck();
    }
    public void urlCheck() {
        String fileName = "http://XXX/XXX.htm";
        try {
            URL url = new URL(fileName);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.connect();
            int status = conn.getResponseCode();
            if(status == 200) {
                System.out.println("success");
            }else{
                System.out.println("fail");
            }
            conn.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1