我试过不行, java的帮助文档也有说,//////////////////////////////////////////////////////// public String readLine() throws IOException Reads the next line of text from the input stream. It reads successive bytes, converting each byte separately into a character, until it encounters a line terminator or end of file; the characters read are then returned as a String. Note that because this method processes bytes, it does not support input of the full Unicode character set. ~~~~~~~~~~~~~~~~~~~~~~~ ////////////////////////////////////////////////////////
兄弟你查的是什么文档?你好好看看: java.io Class BufferedReader java.lang.Object java.io.Reader java.io.BufferedReaderreadLine public String readLine() throws IOExceptionRead a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached Throws: IOException - If an I/O error occurs 这个方法是以行为读取单位的只有遇到'\n'或'\r'时才此行读取这与中文还是英文或是日文并没有关系.关键在于你要以正确的字符集与读取的内容相对应,或进行相应转换. 上面 newman0708(nch) 给的代码就可以读取中文!你试试......
BufferedReader in;
FileReader file;
String s;
this.m_buffFileContent=new StringBuffer();
try{
if(this.m_strFilepath=="")return null;
File f=new File(this.m_strFilepath );
file=new FileReader(f);
in=new BufferedReader (file);
while((s=in.readLine ())!=null)
this.m_buffFileContent.append (s+"\r\n");
in.close() ;
}catch(IOException exp){}
//catch(FileNotFoundException e){}
return this.m_buffFileContent .toString() ;
}我好像没有遇到过只能读英文,不能读中文的情况,可能我没有注意,你再试试。
java的帮助文档也有说,////////////////////////////////////////////////////////
public String readLine()
throws IOException
Reads the next line of text from the input stream. It reads successive bytes, converting each byte separately into a character, until it encounters a line terminator or end of file; the characters read are then returned as a String. Note that because this method processes bytes, it does not support input of the full Unicode character set.
~~~~~~~~~~~~~~~~~~~~~~~
////////////////////////////////////////////////////////
java.io
Class BufferedReader
java.lang.Object
java.io.Reader
java.io.BufferedReaderreadLine
public String readLine()
throws IOExceptionRead a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
这个方法是以行为读取单位的只有遇到'\n'或'\r'时才此行读取这与中文还是英文或是日文并没有关系.关键在于你要以正确的字符集与读取的内容相对应,或进行相应转换.
上面 newman0708(nch) 给的代码就可以读取中文!你试试......
是不是太马虎了?
我也推荐用:RandomAccessFile
如果确实奇怪,如果真的不行
那你就转码,但是建议仔细看看文档,本来没有编码问题,如果转,还不知道哪里又出问题了呢
/**
* 这个类的功能是对字符串进行编码转换,定义了两种iso8859-1和gb2312
*/public class JCEncodingConverter extends Trace
{
private static JCEncodingConverter ref = new JCEncodingConverter();
/* 定义字符串编码 */
String ENCODING_ISO = "iso8859-1";
String ENCODING_GB = "gb2312";
/* 获得字符串的ISO编码 */
public static String getISO(String str_old)
{
String str_new = str_old;
try
{
byte[] temp = str_old.getBytes(ref.ENCODING_ISO);
str_new = new String(temp);
}
catch(Exception e)
{}
return str_new;
}
/* 获得字符串的GB编码 */
public static String getGB(String str_old)
{
String str_new = str_old;
try
{
byte[] temp = str_old.getBytes(ref.ENCODING_GB);
str_new = new String(temp);
}
catch(Exception e)
{}
// 记录日志
ref.InsertTrace(Trace.DEF_TR_INFO,"getGB():End");
return str_new;
}
/* 测试用 */
public static void main(String[] args)
{
String str = "测试用字符串";
System.out.println(JCEncodingConverter.getGB(str));
System.out.println(JCEncodingConverter.getISO(str));
}
}
结贴..........