How to read data from URL in java code examples

    public String getURLData(String realPath, String actionUrl){

        StringBuffer buf=new StringBuffer();

        try{


            URL myurl = new URL(actionUrl);

            URLConnection con = myurl.openConnection();

            BufferedReader in = new BufferedReader(

                                    new InputStreamReader(

                                            con.getInputStream()));

            String inputLine;

            while ((inputLine = in.readLine()) != null) {

                buf.append(inputLine);

            }

            in.close();

            buf=new StringBuffer(buf.toString());//change special character in data

        }

           catch(java.net.ConnectException e1){
               e1.printStackTrace();
           }

           catch (Exception e) {

                e.printStackTrace();
            }

       return buf.toString();      

    }

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Shallow Copy Deep Copy Java example

Database Connection using NODE JS example