惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
N
Netflix TechBlog - Medium
C
Check Point Blog
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
I
InfoQ
Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
腾讯CDC
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
V
V2EX
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
B
Blog

博客园 - 系咪噶

最近转战东软 apache 新建虚拟机 +Zend Framework建立 Apache + php 配置 php基础教程之PHP面向对象技术(全面讲解) 今日无事,将一同志之毕设完结 SQL查询基本练习1:(作业) SQL Server 高级应用(周六讲座) 面向对象之CoreJava(第一课) CVS的使用(一课时) PL/SQL第三课(学习笔记) PL/SQL第二课(作业) PL/SQL第二课(学习笔记) PL/SQL第一课(学习笔记) Oracle第五课(学习笔记) Oracle第四课(学习笔记) 全步骤安装mysql SQL Server 存储过程的分页 无法连接到Visual Studio 的Localhost Web服务器 Oracle第三课(学习中笔记)
[JAVA基础]流文件读写文件编码转换
系咪噶 · 2012-10-29 · via 博客园 - 系咪噶

将本地的gbk文件流读取变换成utf-8文件

    

public static void gbk2utf8(String targetFile,String outFile)
    {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try
        {
            InputStream is = new FileInputStream(targetFile);
            OutputStream os = new FileOutputStream(outFile);
            br = new BufferedReader(new InputStreamReader(is,"gbk"));
            String str = "";
            bw = new BufferedWriter(new OutputStreamWriter(os,"utf-8"));
            while((str = br.readLine())!=null)
            {
                bw.write(str);
                bw.newLine();   
            }
        
        } catch (Exception e)
        {
            e.printStackTrace();
        } 
        finally
        {
            try
            {
            
                if(null!=bw)
                    bw.close();
                if(null!=br)
                    bw.close();
            } catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

posted @ 2012-10-29 11:36  系咪噶  阅读(859)  评论()    收藏  举报