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.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
public class Main {
String filesDir = "";
String filesNDir = "";
public static void main(String args[]) throws IOException {
cp("C:/Documents and Settings/Administrator/workspace/ABC/",
"C:/Documents and Settings/Administrator/workspace/ABC2",
"UTF-8", "GBK");
}
static void cp(String baseDir, String ndir, String code1, String code2)
throws IOException {
File file = new File(baseDir);
if(file.isDirectory())
new File(ndir).mkdirs();
if (file.isDirectory()) {
String list[] = file.list();
for (String f : list) {
cp(baseDir + "/" + f, ndir + "/" + f, code1, code2);
}
} else {
if (baseDir.indexOf(".php") > 0 || baseDir.indexOf(".html") > 0 || baseDir.indexOf(".js") > 0 || baseDir.indexOf(".xml") > 0 || baseDir.indexOf(".css") > 0) {
convert(baseDir, ndir, code1, code2);
InputStreamReader read = new InputStreamReader(
new FileInputStream(baseDir), code1);// 或者UNICODE,UTF-16
BufferedReader reader = new BufferedReader(read);
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
read.close();
}
}
}
public static void convert(String infile, String outfile, String from,
String to) throws IOException, UnsupportedEncodingException {
// set up byte streams
InputStream in;
if (infile != null)
in = new FileInputStream(infile);
else
in = System.in;
OutputStream out;
if (outfile != null)
out = new FileOutputStream(outfile);
else
out = System.out;
// Use default encoding if no encoding is specified.
if (from == null)
from = System.getProperty("file.encoding");
if (to == null)
to = System.getProperty("file.encoding");
// Set up character stream
Reader r = new BufferedReader(new InputStreamReader(in, from));
Writer w = new BufferedWriter(new OutputStreamWriter(out, to));
// Copy characters from input to output. The InputStreamReader
// converts from the input encoding to Unicode,, and the
// OutputStreamWriter
// converts from Unicode to the output encoding. Characters that cannot
// be
// represented in the output encoding are output as '?'
char[] buffer = new char[4096];
int len;
while ((len = r.read(buffer)) != -1)
w.write(buffer, 0, len);
r.close();
w.flush();
w.close();
}
}
写道
分享到:
相关推荐
相当不错的文件编码转换工具,批量转换,省时省力。极力推荐!!
linux 字符集转换脚本,稍微修改脚本即可批量修改文件解决字符编码导致的文件乱码问题
非常好用的一款编码转换软件,批量修改,不论是单文件还是文件夹,直接拖入就可修改成自己希望的编码方式,适合程序员在不同编码格式的电脑直接传输文件时转换,绿色无毒,自用,放心
可批量对如txt格式的文本大进行字符集编码的更改,方便编码转换
测试使用说明: 1。将 字符集编码格式为 GB2312 的文件 test0.java,test...使用本工具可以对 Linux 下文件的字符集编码格式进行批量转换。只需适当配置一下,可以批量处理各种文件格式的文件,如 *.txt,*.java 等等。
文件编码格式批量转换,转UTF-8等编码加
编码转换工具,用于给各种字符集的文件自动,批量转换编码
这个插件用于转换java文件的编码格式,我当时是用反编译软件批量反编译了项目部分文件,其字符集为UTF-8,与其他项目路径下的字符集不同,用该插件批量转换为GBK了
在多人开发的合作过程中,由于前期未意识到需要统一源代码的字符集编码的问题 而由于ide的不同和个人喜好的不同,开发过程中有的人使用了utf-8,有的人使用了GBK.. 如果等整合的时候才发现这个问题,麻烦就大了,记事本...
(转载)GBK编码的文件和UTF8编码方式的转换,支持批量转换。当eclipse编码方式为GBK,其中包含中文的注释,这个工具适合批量转换成UTF编码
特性 支持各种编程语言的语法高亮 支持ANSI、UTF8、UTF16及多种编码字符集之间的自由切换和转换 编码格式自动识别 代码折叠 剪贴板历史记录 增强的查找和替换 ...文本编码转换和文件编码批量转换功能
-----MySQL 字符集: UTF-8 Unicode (utf8) -----> 2)建表时候一切默认;至于导入*.SQL没试应该是不用动什么<!-----MySQL 字符集: UTF-8 Unicode (utf8) -----> 3)在 php 文件头部加入 ; charset=utf-8"></HEAD> ...
包括十几种方式批量重命名文件,批量修改文件内容、属性、时间、快捷方式信息、音乐标签,批量创建文件和文件夹、智能归档,批量分割和合并文件,批量下载网络图片、批量转换图片尺寸和格式、截取区域和插入水印等等...
本资源利用多个实例,如打印文件路径、输出控制字符、显示特殊字符等,展示了C语言转义字符的用法和作用,以及相关的概念和知识,如ASCII码、字符集、字符串等。本资源适合C语言教学和学习的教师和学生使用,帮助...
可以把任意字符集编码转换为其他的字符集字符集,支持批量转换。启动方法:在命令行输入java -jar zhcode.jar
在多人开发的合作过程中,由于前期未意识到需要统一源代码的字符集编码的问题 而由于ide的不同和个人喜好的不同,开发过程中有的人使用了utf-8,有的人使用了GBK.. 如果等整合的时候才发现这个问题,麻烦就大了,...
字符集探测是著名的老大难问题,就是说,怎样在不知道字符编码的情况下,探测出文本是什么编码,什么字符集。这个问题很难。 所以,你看到的绝大多数转字符集的程序,都是GBK->UTF-8,GBK->BIG5,这种,必须要你...
提供了对doc/ppt/txt/asp/html等文档进行智能字符批量替换(支持正则,Word通配符),对txt文本行的添加、删除、提取、统计分割等的处理,对doc/txt类型互转,对xls表合并 ,对ppt转word,Office文档密码筛查, txt...
当vs2013只支持unicode字符集,打开vc6.0版本的工程后,需要把字符串的形式从 "aaa" 转换成 _T("aaa"),手工转换工作量大,本程序可实现批量转换,操作方法是将原文件内容复制过来,点击转换按钮,然后再复制回去即可...