銆愯浆杞姐�戣В鏋怷ML鍚勭寮傚父

The markup in the document following the root element must be well-formed.

XML鏄爲鐘剁粨鏋勶紝涓�瀹氳鏈変釜鏈�澶栧眰鐨勬爣绛惧浣�

Invalid byte 1 of 1-byte UTF-8 sequence 寮傚父鍒嗘瀽鍜岃В鍐�

鈥渙rg.dom4j.DocumentException: Invalid byte 1 of 1-byte UTF-8 sequence.鈥濆紓甯稿垎鏋愬拰瑙e喅锛�

鍒嗘瀽锛�

璇ュ紓甯哥敱涓嬮潰鐨剅eader.read(file);璇彞鎶涘嚭锛�

SAXReader reader = new SAXReader();

Document doc = reader.read(file);

浜х敓杩欎釜寮傚父鐨勫師鍥犳槸锛�

鎵�璇荤殑xml鏂囦欢瀹為檯鏄疓BK鎴栬�呭叾浠栫紪鐮佺殑锛岃�寈ml鍐呭涓嵈鐢ㄦ寚瀹氱紪鐮佷负utf-8锛屾墍浠ュ氨鎶ュ紓甯镐簡锛�

瑙e喅鏂规硶锛�

鍦ㄨВ鏋怷ML鍓嶏紝灏哫ML缂栫爜涓篣TF-8銆�

濡傦細req.setCharacterEncoding("UTF-8");

濡傦細new ByteArrayInputStream(submitDataParam.getBytes("UTF-8"))

Invalid byte 2 of 2-byte UTF-8 sequence 寮傚父鍒嗘瀽鍜岃В鍐�

鍘熷洜锛�

saxReader.read()璇诲彇鐨勬祦涓寘鍚腑鏂囨姤閿欙細

瑙e喅锛�

SAXReader saxReader =newSAXReader();

byte[] bytes = requestMsg.getBytes();

InputStream in =newByteArrayInputStream(bytes);

InputStreamReader strInStream =newInputStreamReader(in,"GBK"); //鍗冲湪璇绘祦鏃舵寚瀹氱紪鐮�

Document document = saxReader.read(strInStream);

你可能感兴趣的:(銆愯浆杞姐�戣В鏋怷ML鍚勭寮傚父)