Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static InputStream getHTTPInputStream(String url) {
        try {
            URL urlObj = null;
            urlObj = new URL(url);

            HttpURLConnection urlConnection = null;

            urlConnection = (HttpURLConnection) urlObj.openConnection();

            urlConnection.connect();

            int response = urlConnection.getResponseCode();

            if (response != 200) {
                return null;
            }

            return urlConnection.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}