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);
        }
}

 

相关文章:

  • 2021-04-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-11-17
  • 2022-01-27
猜你喜欢
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
相关资源
相似解决方案