Infolinks In Text Ads

Jun 27, 2010

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();      

    }

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...