zoukankan      html  css  js  c++  java
  • java URI 编码解码

     1 import java.io.UnsupportedEncodingException;
     2 /**
     3  * url转码、解码
     4  */
     5 public class UrlUtil {
     6     private final static String ENCODE = "GBK"; 
     7     /**
     8      * URL 解码
     9      *
    10      */
    11     public static String getURLDecoderString(String str) {
    12         String result = "";
    13         if (null == str) {
    14             return "";
    15         }
    16         try {
    17             result = java.net.URLDecoder.decode(str, ENCODE);
    18         } catch (UnsupportedEncodingException e) {
    19             e.printStackTrace();
    20         }
    21         return result;
    22     }
    23     /**
    24      * URL 转码
    25      */
    26     public static String getURLEncoderString(String str) {
    27         String result = "";
    28         if (null == str) {
    29             return "";
    30         }
    31         try {
    32             result = java.net.URLEncoder.encode(str, ENCODE);
    33         } catch (UnsupportedEncodingException e) {
    34             e.printStackTrace();
    35         }
    36         return result;
    37     }
    38 
    39     /**
    40      * 
    41      */
    42     public static void main(String[] args) {
    43         String str = "测试1";
    44         System.out.println(getURLEncoderString(str));
    45         System.out.println(getURLDecoderString(str));
    46         
    47     }
    48 
    49 }
  • 相关阅读:
    AI CV 会议2018
    ubuntu 更改默认亮度
    ubuntu安装latex
    过滤文件代码 python
    ubuntu安装pycharm桌面快捷方式
    Ubuntu 14.04 鼠标消失解决方案
    ffmpeg常用命令
    FFMPEG 在ubuntu下的安装与使用
    pragma once
    chrono--高精度计时
  • 原文地址:https://www.cnblogs.com/the-wang/p/9049217.html
Copyright © 2011-2022 走看看