67,512
社区成员
发帖
与我相关
我的任务
分享
FileInputStream is = new FileInputStream(new File("utf8.txt") );
InputStreamReader reader = new InputStreamReader(is, "UTF-8");
public static void ansiToUTF8(File f) throws IOException{
if(!f.isFile()){
return;
}
byte[] bs=new byte[(int)f.length()];
FileInputStream fis=new FileInputStream(f);
try{
int io=0;
while(io<bs.length){
int n=fis.read(bs,io,bs.length-io);
if(n<=0){
break;
}
}
}
finally{
fis.close();
}
String s=new String(bs);
bs=s.getBytes("UTF-8");
FileOutputStream fos=new FileOutputStream(f);
try{
fos.write(bs);
}
finally{
fos.close();
}
}