Java String Encode encode(String source, String charsetFrom, String charsetTo)

Here you can find the source of encode(String source, String charsetFrom, String charsetTo)

Description

encode

License

Apache License

Declaration

public static String encode(String source, String charsetFrom, String charsetTo) 

Method Source Code

//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);
    }
}

Related

  1. encode(String s)
  2. encode(String s)
  3. encode(String s)
  4. encode(String s, String enc)
  5. encode(String s, String encoding)
  6. encode(String src)
  7. encode(String src, String charset)
  8. encode(String str)
  9. encode(String str, int start, int end, Writer writer)