日期:2014-05-20  浏览次数:20639 次

新手求助,文件回车编码转换
以下我是将网页中某部分的文字取出来,放入生成的txt文件,转换后回车不正常,显示一个小黑方块,请大家帮忙看看,这个应该是编码问题

读文件
String   temp   =   " ";
int   lenght   =   fileinputstream.available();
byte   bytes[]   =   new   byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
temp   =   new   String(bytes);

转p标记为空格
temp   =   temp.replaceAll( " <p> ",   "\n ");

写文件
String   pathandname   =   "D://temp1// "   +   title   +   ".txt ";
FileOutputStream   output   =   new   FileOutputStream(pathandname);
output.write(temp.getBytes( "utf-8 "));
output.close();
output   =   null;

------解决方案--------------------
回车换行的编码是不会有编码问题的!你不要用txt打开,你用写字板打开估计就对了,或者用word打开哈! 文本文件打开可能会有这个问题!
------解决方案--------------------
"\n "换成 "\r\n "就好了
------解决方案--------------------
temp = temp.replaceAll( " <p> ", "\n ");

"\n "换成 "\r\n "就好了


试过了?
------解决方案--------------------
\n是ASCII码,在Unicode里加入ASCII码当然是黑点了哦.楼上的方法你试试.呵呵.