读取UTF-8: package txt; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.InputStream; public class Utf8ReadLines { private int sentents,lines;//读取的行数 private String content="";//获取的文件内容 private int readsize;//已读的大小 public String getContent() { return content; } public int getReadsize() { return readsize; } public Utf8ReadLines(int lines){ sentents=lines; this.lines=lines; } /** * 按行读取UTF-8文本 * @param name 文件路径 * @param jump 跳过的大小 * @return */ public Utf8ReadLines Read_Line(String name,int jump) { int ic; InputStream in = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); byte[] myData; try { in = getClass().getResourceAsStream(name); in.skip(3+jump);//if( tmp[0] == -17 && tmp[1] == -69 && tmp[2] == -65 ) if (in != null) { while ((ic = in.read()) > 0) { dos.write(ic); if(ic==13){// '/r' sentents--; if(sentents<=0) break; } } myData = baos.toByteArray(); readsize=myData.length+3; content = new String(myData, "UTF-8"); in.close(); } dos.close(); baos.close(); } catch (Exception e) { e.printStackTrace(); } finally { in = null; dos = null; baos = null; } sentents=lines; return this; } } 读取Unicode: package txt; import java.io.IOException; import java.io.InputStream; public class UnicodeReadLines { private String content="";//内容 public String getContent() { return content; } private int readsize;//已读大小 public int getReadsize() { return readsize; } private int lines,sentents; public UnicodeReadLines(int lines){ this.lines=lines; sentents=lines; } /** * 按行读取Unicode * @param resource 文件名 * @param jump 跳过的大小 * @return */ public UnicodeReadLines Read_Line(String resource,int jump) { InputStream is = null; StringBuffer stringbuffer = new StringBuffer(""); try { is = getClass().getResourceAsStream(resource); is.skip(2+jump); for (int count = 0; count < 1024000; count += 2) {//中间的尽量给大一些 //读取一个字符 byte[] two = new byte[2]; is.read(two); int l = two[0]; int h = two[1]; char c = (char) ((l & 0xff) | ((h << 8) & 0xff00)); stringbuffer.append(c); if(c=='/r'){ sentents--; if(sentents<=0){ readsize=jump+2+count;//统计已读大小 break; } } } is.close(); content = stringbuffer.toString(); sentents=lines; } catch (IOException ex) { ex.printStackTrace(); } finally { is = null; } return this; } } 初始化时就可以将显示的行数传进. 使用时只需要用getContent()即可得到内容,注意控制的skip大小.