txt文件中有繁体字.
在jsp中显示的是?号.怎么将繁体字显示出来,请大家帮忙看下
in = new BufferedReader(new FileReader(strAbsPath + "//ttt.txt"));
String f="~~~";
while((str = in.readLine()) != null){
String tos = str;
应该怎么转?
将txt文件另存为.在另存对话框中,选择编码项为UTF-8.
再将读取到的内容字符串进行编码.转换为UTF-8的格式.
[code="java"]
byte[] bytes = str.getBytes("UTF-8");
String result = new String(bytes, "UTF-8");
[/code]
指定字符集。比如big5。
String encoding = "Big5";
Reader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(filename),
encoding
)
);
[code="java"]
import java.io.*;
public class ReadFile {
public static void readTextFile(){
try{
File file = new File("file.txt"); //路径你要具体指定一下!
String line = null;
InputStreamReader read=new InputStreamReader(new FileInputStream(file),"GBK");
BufferedReader reader=new BufferedReader(read);
while( (line=reader.readLine())!=null){
System.out.println(line);
}
reader.close();
read.close();
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
readTextFile();
}
}
[/code]
需要搞清楚txt文件里的编码是什么才好说清楚。
你是notepad打开的?
如果是就另存,出现文件编码是utf的则是utf8
如果是iso或西欧的则可能是big5或则gbk,是big5需要转码使用Java以字节读入,然后new String(bytes,“big5”);这样内存里就是正确的unicode了,直接输出io可用。
先将txt文件save as为Encoding是UTF-8的文件
再将jsp中的pageEncoding和charset的值改为UTF-8
上面程序应该是可以的