Created
May 20, 2018 07:00
-
-
Save sutra/4ff19a3aaedc684d159fe3b482ec5db1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.oxerr.sandbox; | |
import java.io.UnsupportedEncodingException; | |
import java.net.URLDecoder; | |
import java.net.URLEncoder; | |
import java.nio.charset.StandardCharsets; | |
public class URLEncode { | |
public static void main(String[] args) throws UnsupportedEncodingException { | |
final String pythonEncoded = "RIFF%AC%89%03%00WAVEfmt+"; | |
final String original = URLDecoder.decode("RIFF%C2%AC%C2%89%03%00WAVEfmt+", StandardCharsets.UTF_8.name()); | |
System.out.println(original); | |
final String iso_8859_1 = URLEncoder.encode(original, StandardCharsets.ISO_8859_1.name()); | |
System.out.println(iso_8859_1); | |
System.out.println(pythonEncoded.equals(iso_8859_1)); | |
// 结论: | |
// Python 使用了 iso-8859-1 charset | |
// Java 使用了 UTF-8 charset | |
// 导致了楼主在 Python 和 Java 中得到了不同的结果 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment