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

ANSI编码文本文件转换成UTF-八

2013-11-09 
ANSI编码文本文件转换成UTF-8?package org.apache.hadoop.examplesimport java.io.BufferedReaderimport

ANSI编码文本文件转换成UTF-8

?

package org.apache.hadoop.examples;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.UnsupportedEncodingException;import java.io.Writer;public class Convert {public static void main(String[] args) throws UnsupportedEncodingException, IOException {File orgi = new File(args[0]);File dest = new File(args[1]);if(orgi.isDirectory()) {File[] files = orgi.listFiles();for(File file : files) {convert(file, new File(dest, file.getName()));}}}public static void convert(File src, File dest) throws IOException {BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(src), "GBK"));Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dest), "utf-8"));String line = null;while((line = br.readLine()) != null) {System.out.println(line);writer.write(line);}writer.flush();writer.close();br.close();}public static String convert(String text) throws UnsupportedEncodingException {return new String(text.getBytes("GBK"));}}
?

热点排行