Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;
import java.nio.charset.Charset;

import android.text.TextUtils;

public class Main {

    public static String encodeURL(String raw) {
        return encodeURL(raw, null);
    }

    public static String encodeURL(String raw, String charsetName) {
        if (raw == null) {
            return null;
        }
        try {
            if (TextUtils.isEmpty(charsetName)) {
                charsetName = Charset.defaultCharset().displayName();
            }
            return URLEncoder.encode(raw, charsetName);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
}