package com.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
/**
* 类描述: 批量转换文件编码格式
*/
public class EncodeConverter {
// 源文件编码
private static String srcEncode = "gbk";
// 输出文件编码
private static String desEncode = "utf-8";
/**
* @param infile 源文件路径
* @param outfile 输出文件路径
* @param from 源文件编码
* @param to 目标文件编码
* @throws IOException
* @throws UnsupportedEncodingException
*/
public static void convert(String infile, String outfile, String from, String to) throws IOException, UnsupportedEncodingException {
//BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(infile), from));
//PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), to)));
InputStream ins = new FileInputStream(infile);
OutputStream ous = new FileOutputStream(outfile);
/*String reading;
while ((reading = in.readLine()) != null) {
out.println(reading);
}*/
byte[] b = new byte[(int)new File(infile).length()];
while(ins.read(b, 0, b.length) != -1) {
String tmp = new String(b,from);
ous.write(tmp.getBytes(to));
}
ous.close();
ins.close();
}
public static void main(String[] args) {
if(!(args.length == 2)){
System.out.println("[ 文件编码转换错误 ]====================参数个数不正确");
}
String infile = args[0];
String outfile = args[1];
File file = new File(infile);
if(!file.exists()) {
System.out.println("[ 文件编码转换错误 ]====================" + file.getAbsolutePath()+" 不存在====================");
}
try {
convert(infile, outfile, srcEncode, desEncode);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
分享到:
相关推荐
批量文件编码格式转换工具.zip批量文件编码格式转换工具.zip 批量文件编码格式转换工具.zip批量文件编码格式转换工具.zip 批量文件编码格式转换工具.zip批量文件编码格式转换工具.zip 批量文件编码格式转换工具.zip...
文件编码格式转换工具.exe
Linux下查看文件编码,文件编码格式转换和文件名编码
从网上下载的源码经常会出现源码文件编码格式和IDE默认的格式不匹配的情况,特别是源码文件中有中文汉字(包括注释)的情况下,特特别是不同IDE、不同系统下编辑的源码。虽然IDE自带可以修改文件的编码格式,但是...
批量字符编码转换工具是文件编码转换的最佳工具。是您必备的unicode编码转换器,它帮助您快速完成编码批量转换。 utf8 转gb2312编码转换举例,编码转换软件工作原理 比如要把D:\web目录下的php文件和html文件由utf8...
#批量文件编码格式转换工具 ##简介 最近开始学习使用Android Studio,因为它的方便易用,我打算以后就不在使用ADT的方式编写Android项目了。当从Eclipse项目向AS项目迁移时遇到了一个问题,就是文件编码格式的问题,...
eclipse默认编码为gbk开发一段时间需要修改成utf-8,写个脚本批量处理文件编码格式,也可以批量替换文本内容;
是否下载了一个文本文件打开是乱码呢?是否手机电子书编码需要转换呢...原创文件编码转换器。Java编写,多平台运行。源码奉献。啊啊啊啊啊啊。。。只要1分。如果不想给分,可以email我 iamjemy@gmail.com邮件发送给你。
能够集成到Source Insight中,解决JAVA文件乱码问题
Java写的一个小程序,用于批量转换GBK编码的java源文件为UTF-8编码格式
Linux查看文件编码格式及文件编码转换
Qt5.9开发的文件编码转换。该工具我用来在Windows7下面VS2015编译器与MinGW编译器编码转换。MinGW编译器使用UTF-8编码,VS2015使用GB2312编码。 预编译头文件缺失,将头文件替换为 #include #include #include #...
批量转换文件编码格式为UTF-8工具.zip 支持多层文件夹替换! 使用说明: 1.文件根目录:即您要转码的文件所在根目录 2.转码文件目录:即您转码后的文件所在目录 3.转码文件后缀:指[文件根目录]下,需要转码的文件后缀,...
转换器的使用方法很简单,只需把你要转换的txt文件放到任意一个文件夹里面,然后运行txt文件编码批量转换器,选择你要转换的编码,然后点击选择文件夹按钮,在弹出窗口中选择你放txt文件的那个文件夹,然后确定。...
批量转换文件编码 超级批量编码转换 批量转换编码 编码批量转换工具 批量转换txt编码 linux 批量转换编码 编码格式批量转换 php 字符编码转换 字符编码转换 java 字符编码转换
2,文件编码自动识别,所以使用的时候不用提供原文件的编码;识别不了不会转换,保证项目文件的安全 3,支持utf-8-bom编码 4,兼容Linux & Windows & Mac系统 5,不用安装,只要机器有JDK就可以使用 需要源码的请...
C#:批量修改文本编码为UTF-8(含源码),可将指定文件夹下的所有是.txt、.cs、.lua后缀的文件(需要更多支持可自行修改)的编码格式修改为UTF-8,VS2013的项目。
文件编码批量转换器 支持文件编码批量转换 需要.framework的支持