首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

把资料从ANSI转成utf-8

2012-12-20 
把文件从ANSI转成utf-8package liuimport java.io.*public class FileProcess {/** * @param args */pub

把文件从ANSI转成utf-8
package liu;
import java.io.*;
public class FileProcess {

/**
* @param args
*/
public static void main(String[] args) {


        FileInputStream fis = null;
        FileOutputStream fos = null;
        try{
            fis = new FileInputStream(new File("f:\\FromNC.txt"));
            fos = new FileOutputStream(new File("f:\\b.txt"));
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            String str = new String(buffer, "GBK");
            fos.write(str.getBytes("utf-8"));
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            if(fis != null){
                try{
                    fis.close();
                }catch(Exception e){
                   
                }
            }
            if(fos != null){
                try{
                    fos.close();
                }catch(Exception e){
                }
            }
        }
}
}

热点排行