Posts

Showing posts from June 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();      

    }

How to convert date in own format java code example

public static String getFormatedDate(String dateFormate, Date date){

        try{
             DateFormat dft = new  SimpleDateFormat(dateFormate);
             return dft.format(date);
        }catch(Exception e){
            e.printStackTrace();
        }

        return null;
    }

Recent Post

Recent Posts Widget