jdk有一个关于UTF-8的bug
所以加了一句 br.skip(1);
bugID:
http://bugs.java.com/view_bug.do?bug_id=4508058
public static void main(String[] args) {
StringBuffer buffer=new StringBuffer();
try {
FileInputStream fis=new FileInputStream("test.txt");
InputStreamReader isr=new InputStreamReader(fis,"UTF-8");
BufferedReader br=new BufferedReader(isr);
String line=null;
br.skip(1);
while ((line=br.readLine())!=null) {
buffer.append(line);
buffer.append("\r\n");
}
buffer.delete(buffer.length()-2,buffer.length());
br.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(buffer);
try {
FileOutputStream fos=new FileOutputStream("test1.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos);
osw.write(buffer.toString());
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}