Here you can find the source of encode(String source, String charsetFrom, String charsetTo)
public static String encode(String source, String charsetFrom, String charsetTo)
//package com.java2s; /**// w w w.j a v a 2s . c o m * Copyright (c) 2005-2010 jeysan.com * * Licensed under the Apache License, Version 2.0 (the "License"); * * $Id: EncodeUtils.java 1211 2010-09-10 16:20:45Z shally $ */ import java.io.UnsupportedEncodingException; public class Main { private static final String DEFAULT_URL_ENCODING = "UTF-8"; public static String encode(String source, String charsetFrom, String charsetTo) { try { return new String(source.getBytes(charsetFrom), charsetTo); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return source; } public static String encode(String source, String charsetFrom) { return encode(source, charsetFrom, DEFAULT_URL_ENCODING); } }