尝试读取文件时获取垃圾数据
Getting garbage data while tring to read a file
URL url = new URL("http://localhost:8082/newsletter/comments/"+rs.getString("articlename"));
BufferedReader in = new BufferedReader( new InputStreamReader(url.openStream()));
String buf=" ";
while((buf = in.readLine())!= null){
out.write(buf);
out.flush();
}
in.close();
这就是我正在处理的代码。正在读取的文件在页面上显示垃圾值。显示的内容很大,而文件只有一行。请帮忙
以下是显示的垃圾邮件示例:
PK!Ýü?7f [Content_Types].xml ¢( ´TËnÂ0¼Wê?D¾V?¡?ªªú8¶H¥`ìXõKöòúûnDUA*å)YïÌììÄ?ÑÚ?l 1iïJÖ/z,'½ÒnV²?ÉK~ϲ?Â)a¼??m ±Ñðúj0ÙHu»T²9bxà<É9X?ÀQ¥òѤ×8ãAÈO1~ÛëÝqé?Ãk6$N{9?êÍ+P9Y ¢?vuÇGD²ìÃï?»ÆoR??wàͳ¶ÌIÊ?~???8?ïWòZè?"V0}¿?ûßÀ»?´ù?>þÁ?ýuQwHoî·áÿÿPK!?·óN_rels/.rels ¢( ??ÛJA?ïßaÈ}7Û"ÒÙÞH¡w"ë??ìw̤ھ½£ ºPÛ^æôçËOÖ???Ô;§<¯aYÕ Ø?`Gßkxm·?PYÈ[??gGΰinoÖ/"f3°£\?ȾTº?I S??Ìõ?«º¾ÇôW??¦ÚYigï@µÇX6_Ö]7~fïØË?ÈaoÙ.b*lIÆr?j)õ,l0Ï%??b¬6ài¢ÕõDÿ_???, ¡ ?Ïó|u?Z^tÙ¢yǯ;!Y,}{ûC?³/h>ÿÿPK!Öd³Qú1word/_rels/document.xml.rels ¢( ¬?ÍjÃ0?ï?¾?Ø{-;ý¡?ȹ?@®û?½þ¡²$´?¶~ûCR?÷â?`Fhæ?´?íwoÄ'ê?U?%)´¥«:Û(x/vwÏ ?µ´qH°Íoo6¯h4ÇCÔv?DL±¤ eök)©l±×?8?6îÔ.ô?£?ôºüÐÊU?>É0Í?ü"Sì+a_Ý?(?ÿÏvuÝ?øâÊc??¯TÈ/<¼!s¼ÅXd3?
要阅读 word 文档 (docx),您需要使用 Apache POI framework. You will specifically want to use the XWPF
and HWPF
portion, the documentation can be found here.
URL url = new URL("http://localhost:8082/newsletter/comments/"+rs.getString("articlename"));
BufferedReader in = new BufferedReader( new InputStreamReader(url.openStream()));
String buf=" ";
while((buf = in.readLine())!= null){
out.write(buf);
out.flush();
}
in.close();
这就是我正在处理的代码。正在读取的文件在页面上显示垃圾值。显示的内容很大,而文件只有一行。请帮忙
以下是显示的垃圾邮件示例:
PK!Ýü?7f [Content_Types].xml ¢( ´TËnÂ0¼Wê?D¾V?¡?ªªú8¶H¥`ìXõKöòúûnDUA*å)YïÌììÄ?ÑÚ?l 1iïJÖ/z,'½ÒnV²?ÉK~ϲ?Â)a¼??m ±Ñðúj0ÙHu»T²9bxà<É9X?ÀQ¥òѤ×8ãAÈO1~ÛëÝqé?Ãk6$N{9?êÍ+P9Y ¢?vuÇGD²ìÃï?»ÆoR??wàͳ¶ÌIÊ?~???8?ïWòZè?"V0}¿?ûßÀ»?´ù?>þÁ?ýuQwHoî·áÿÿPK!?·óN_rels/.rels ¢( ??ÛJA?ïßaÈ}7Û"ÒÙÞH¡w"ë??ìw̤ھ½£ ºPÛ^æôçËOÖ???Ô;§<¯aYÕ Ø?`Gßkxm·?PYÈ[??gGΰinoÖ/"f3°£\?ȾTº?I S??Ìõ?«º¾ÇôW??¦ÚYigï@µÇX6_Ö]7~fïØË?ÈaoÙ.b*lIÆr?j)õ,l0Ï%??b¬6ài¢ÕõDÿ_???, ¡ ?Ïó|u?Z^tÙ¢yǯ;!Y,}{ûC?³/h>ÿÿPK!Öd³Qú1word/_rels/document.xml.rels ¢( ¬?ÍjÃ0?ï?¾?Ø{-;ý¡?ȹ?@®û?½þ¡²$´?¶~ûCR?÷â?`Fhæ?´?íwoÄ'ê?U?%)´¥«:Û(x/vwÏ ?µ´qH°Íoo6¯h4ÇCÔv?DL±¤ eök)©l±×?8?6îÔ.ô?£?ôºüÐÊU?>É0Í?ü"Sì+a_Ý?(?ÿÏvuÝ?øâÊc??¯TÈ/<¼!s¼ÅXd3?
要阅读 word 文档 (docx),您需要使用 Apache POI framework. You will specifically want to use the XWPF
and HWPF
portion, the documentation can be found here.