Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.net.URLEncoder;

public class Main {
    /**
     * Encode some text to be used in a URL.
     * @param s the string to encode.
     * @return the string once encoded.
     */
    @SuppressWarnings("deprecation")
    public static String encodeURL(String s) {
        String encodedString;
        try {
            encodedString = URLEncoder.encode(s, "UTF-8");
        } catch (Exception e) {
            encodedString = URLEncoder.encode(s);
        }
        return encodedString.replaceAll("\\+", "%20");
    }
}