首页 > 代码库 > java将文件转为UTF8工具类
java将文件转为UTF8工具类
package hiveTest;import java.io.BufferedReader;import java.io.DataInputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.Writer;public class GBKTransferUTF8 { private static void transferFile(String srcFileName, String destFileName) throws IOException { String line_separator = System.getProperty("line.separator"); FileInputStream fis = new FileInputStream(srcFileName); StringBuffer content = new StringBuffer(); DataInputStream in = new DataInputStream(fis); BufferedReader d = new BufferedReader(new InputStreamReader(in, "GBK"));// , "UTF-8" String line = null; while ((line = d.readLine()) != null) content.append(line + line_separator); d.close(); in.close(); fis.close(); Writer ow = new OutputStreamWriter(new FileOutputStream(destFileName), "utf-8"); ow.write(content.toString()); ow.close(); } public static void main(String[] args) throws IOException { String srcFileName="C:\\Users\\lenovo\\Desktop\\大数据设计\\community_data\\data_example_to_qiaokai.txt"; String destFileName="C:\\Users\\lenovo\\Desktop\\大数据设计\\community_data\\data_example_to_qiaokai-utf8.txt"; GBKTransferUTF8.transferFile(srcFileName, destFileName); }}
java将文件转为UTF8工具类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。