Tag: encode

如何使用utf8字符正确读取url内容?

public class URLReader { public static byte[] read(String from, String to, String string){ try { String text = “http://translate.google.com/translate_a/t?”+ “client=o&text=”+URLEncoder.encode(string, “UTF-8”)+ “&hl=en&sl=”+from+”&tl=”+to+””; URL url = new URL(text); BufferedReader in = new BufferedReader( new InputStreamReader(url.openStream(), “UTF-8”)); String json = in.readLine(); byte[] bytes = json.getBytes(“UTF-8”); in.close(); return bytes; //return text.getBytes(); } catch (Exception e) { return null; […]