Java操作文本文件中的中文

来源:互联网 发布:程序员两个屏幕 编辑:程序博客网 时间:2024/05/01 10:24

Java操作文本文件中的中文

 try{
RandomAccessFile rf=new RandomAccessFile("e://my.txt","rw");
String str="中文";
byte [] b;
b=str.getBytes();
rf.write(b);//中文就写入文本文件了。
}
catch(Exception e){}

try{ 
BufferedReader br=new BufferedReader(new FileReader("e://my.txt"));
while((line=br.readLine())!=null)
{
  System.out.println(line);//读取文件
}}
catch(Exception e){}
 
原创粉丝点击