- 浏览: 241801 次
文章分类
最新评论
package com.action;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class FileUtils extends org.apache.commons.io.FileUtils{
private static final String ENCODE_GBK = "GBK";
private static final String ENCODE_UTF8 = "UTF-8";
public static void convertGBK2UTF8(File file){
convertFileEncode(file, ENCODE_GBK, ENCODE_UTF8);
}
public static void convertUTF82GBK(File file){
convertFileEncode(file, ENCODE_UTF8, ENCODE_GBK);
}
public static void convertFileEncode(File file, String fromEncode, String toEncode){
try {
String str = readFileToString(file, fromEncode);
writeStringToFile(file, str, toEncode);
} catch (IOException e) {
System.out.println("Convert failed. File not exsit?");
e.printStackTrace();
}
}
public static String readFile(String filePath, String encode){
String fileContent = "";
try {
FileInputStream fis = new FileInputStream(filePath);
InputStreamReader isr = new InputStreamReader(fis, encode);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
for(String line = br.readLine(); line != null; line = br.readLine()){
sb.append(line);
}
fileContent = sb.toString();
br.close();
isr.close();
fis.close();
} catch (FileNotFoundException e) {
System.out.println("File not exist:"+filePath);
} catch (IOException e) {
e.printStackTrace();
}
return fileContent;
}
public static String saveFile(String fileContent, String encode, String savePath){
try {
FileOutputStream fos = new FileOutputStream(savePath);
OutputStreamWriter osw = new OutputStreamWriter(fos, encode);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(fileContent);
bw.close();
osw.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("File not exist:"+savePath);
} catch (IOException e) {
e.printStackTrace();
}
return fileContent;
}
public static synchronized void convertDirectory(File dir) throws IOException {
if (!dir.exists() && !dir.isDirectory()) {
throw new IOException("[" + dir + "] not exsit or not a Directory");
}
convert(dir);
}
public static void convert(File dir){
if (dir.canRead() && dir.canWrite()) {
if (dir.isDirectory()) {//Directory
String[] files = dir.list();
if (files != null) {
for (int i = 0; i < files.length; i++) {
convert(new File(dir, files[i]));//递归
}
}
} else {//File
convertGBK2UTF8(dir);
}
}
}
public static void main(String[] args) throws IOException {
// File f = new File("c:/GenericAction.java");
// convertGBK2UTF8(f);
long t1 = System.currentTimeMillis();
File src = new File("D:\\java\\workspace\\settlecash");
convertDirectory(src);
long t2 = System.currentTimeMillis();
System.out.println("转换完成,用时:"+(t2-t1)/1000);
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class FileUtils extends org.apache.commons.io.FileUtils{
private static final String ENCODE_GBK = "GBK";
private static final String ENCODE_UTF8 = "UTF-8";
public static void convertGBK2UTF8(File file){
convertFileEncode(file, ENCODE_GBK, ENCODE_UTF8);
}
public static void convertUTF82GBK(File file){
convertFileEncode(file, ENCODE_UTF8, ENCODE_GBK);
}
public static void convertFileEncode(File file, String fromEncode, String toEncode){
try {
String str = readFileToString(file, fromEncode);
writeStringToFile(file, str, toEncode);
} catch (IOException e) {
System.out.println("Convert failed. File not exsit?");
e.printStackTrace();
}
}
public static String readFile(String filePath, String encode){
String fileContent = "";
try {
FileInputStream fis = new FileInputStream(filePath);
InputStreamReader isr = new InputStreamReader(fis, encode);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
for(String line = br.readLine(); line != null; line = br.readLine()){
sb.append(line);
}
fileContent = sb.toString();
br.close();
isr.close();
fis.close();
} catch (FileNotFoundException e) {
System.out.println("File not exist:"+filePath);
} catch (IOException e) {
e.printStackTrace();
}
return fileContent;
}
public static String saveFile(String fileContent, String encode, String savePath){
try {
FileOutputStream fos = new FileOutputStream(savePath);
OutputStreamWriter osw = new OutputStreamWriter(fos, encode);
BufferedWriter bw = new BufferedWriter(osw);
bw.write(fileContent);
bw.close();
osw.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("File not exist:"+savePath);
} catch (IOException e) {
e.printStackTrace();
}
return fileContent;
}
public static synchronized void convertDirectory(File dir) throws IOException {
if (!dir.exists() && !dir.isDirectory()) {
throw new IOException("[" + dir + "] not exsit or not a Directory");
}
convert(dir);
}
public static void convert(File dir){
if (dir.canRead() && dir.canWrite()) {
if (dir.isDirectory()) {//Directory
String[] files = dir.list();
if (files != null) {
for (int i = 0; i < files.length; i++) {
convert(new File(dir, files[i]));//递归
}
}
} else {//File
convertGBK2UTF8(dir);
}
}
}
public static void main(String[] args) throws IOException {
// File f = new File("c:/GenericAction.java");
// convertGBK2UTF8(f);
long t1 = System.currentTimeMillis();
File src = new File("D:\\java\\workspace\\settlecash");
convertDirectory(src);
long t2 = System.currentTimeMillis();
System.out.println("转换完成,用时:"+(t2-t1)/1000);
}
}
发表评论
-
分布式事务blog
2014-05-08 00:21 619http://coolshell.cn/articles/10 ... -
批量转码工具
2014-04-18 11:52 379find cozy.base -type d -exec ... -
Pull is not possible because you have unmerged files.
2013-02-25 10:24 24608Pull is not possible because y ... -
github中不加入版本控制.gitignore设定
2013-02-21 10:10 1089引自http://www.xiaoche.me/blog/2 ... -
Git/Github使用方法小记
2013-02-19 16:22 925引自http://artori.us/git-github- ... -
linux教程:Git使用技巧篇
2013-02-19 15:32 904引自http://www.jz123.cn/text/212 ... -
linux教程:Git使用基础篇
2013-02-19 15:19 800引自http://www.jz123.cn/text/21 ... -
git/github初级运用自如
2013-02-19 10:13 895之前初学过一点git版本控制工具,利用github做仓 ... -
CentOS下JDK和resin安装配置
2012-09-18 23:26 965引自http://liyaoyi.blog.51cto.com ... -
maven生成web项目时pom配置
2012-05-07 10:44 999配置生成classes与打包war修改 将lib下的包放在项目 ... -
自动生成sqlmap,do,dao,daoimpl
2012-05-07 10:42 930具体看系统
相关推荐
批量文件转码工具,支持GBK,UTF-8转换,window下面使用,亲测可以使用!
批量修改mysql数据库、表、字段编码(gbk到utf8php脚本) 可以把整个数据库、表、字段编码全部从gbk_chinese_ci 到 utf8_general_ci 转换,不会乱码哦 狂拽吊炸天!!!
该程序为绿色程序,运行程序位于自身的文件夹下,点击运行batchiconv,会转换本文件夹的上级文件夹及其递归子文件夹下的所有文件,...控制台下运行方式为:batchiconv.exe gbk utf-8 $dir $dir为你想要转换的文件夹路径
ChangeEncoding change file encoding in batches, now support UTF-8,GBK,UTF-16...1.0 现在能批量处理UTF8(UTF-8)、GBK(GBK)之间的编码转换 20150206 15:51:00 1.1 添加新的编码UTF16LE(UTF-16LE)、UTF16BE(UTF-16
注意,GBK的模板转换为utf-8的时候,一些标点是无法转换的,而这些GBK编码的标点在老外的电脑上是无法显示的。所以有些文件里面需要批量替换一些不能转换的东西。同样,中文网站使用的uft-8模板不是纯utf-8,想翻译...
软件名称:超级批量文本替换(UltraReplace) 版本: 5.0 授权方式:免费软件 功能说明: 文本替换的利器,批量文本替换的不二之选站长必备,挂马网页杀手,支持所有纯ANSI文件支持GBK/Unicode/UTF8编码的htm、html、asp、...
为您提供TXT文件批量修改下载,txt文件批量修改能够对指定文件夹中的多个txt文件内容批量进行查找替换。软件支持GBK、UTF8编码的文件,支持只查找,不替换,获得包含指定内容的文件路径列表。功能介绍 1、对指定...
1、如果你的后台目录不是e/admin,请修改本插件包里的 /upload/e/admin 目录名为你改过的后台目录名; 2、将“upload”目录下的文件上传至帝国CMS系统目录; 3、在浏览器中执行 /e/admin/extend/tagInfo_extract/...
QT 有时是gbk编码,需要统一转成utf-8,这时候你就需要这个工具了。有源码,QT5可以编译通过。
安装此插件之后,会员就可以获得在签名中上传图片的机会。本插件是在炫彩签名图的基础上...如果您是UTF-8的用,请将signature包中discuz_plugin_signature_SC_UTF8.xml文件更名为discuz_plugin_signature.xml然后安装
'* 软件名称:GB/BIG5/UTF-8 文件编码批量转换程序 '* '* 版权信息:此软件由 阿勇(fxy_2002@163.com) 开发,请保留此信息!! '* 免费软件,欢迎使用!请勿用于直接出售或其它商业用途。 '* '* 作者主页:pc-soft....
* 修改文件编码格式,例如:GBK转UTF8 * 支持多级目录 * @param {String} [root_path] [需要进行转码的文件路径] * @param {Array} [file_type] [需要进行转码的文件格式,比如html文件] * @param
本来一开始的思路还是比较清晰,觉得也比较简单,天真的认为用GBK的方式读取出文件内容,然后UTF8写入就好了,可是在实际的操作中我发现我就是太天真了,出现了大量的问题,比如说: 怎么查看文件的编码方式 好吧我...
文本替换的利器,批量文本替换的不二之选,站长必备,挂马网页杀手,支持所有纯ANSI文件,支持GBK/Unicode/UTF8编码的htm、html、asp、java、php等文件,可自定义所支持的文件类型,支持16进制替换,支持单行和多行...
所以自己就写了个程序,批量修改文件编码格式。 代码: 复制代码 代码如下: /** * 修改文件编码格式,例如:GBK转UTF8 * 支持多级目录 * @param {String} [root_path] [需要进行转码的文件路径] * @param {...
简单的编码环境转换工具类,适用于批量修改目录中纯文本代码文件和其他纯文本,例如utf-8转gbk,gbk转utf-8,如果有需要过滤其他文件可自行加入转换过滤规则,下载之后修改一下导包就可以运行成功了。
批量文件编码转换 ,选择一个目录,只识别文本类文件(各种代码文件),识别的是文件头,不是后缀,可以转换成系统支持的所有格式,包括 UTF-8,GBK 等格式。所以只要是文本文件,无论什么后缀都能识别。如有需要...
支持文件批量转换编码,不单纯是修改编码格式,直接是进行编码的格式转换,比如GBK编码格式转换为UTF-8编码格式中文不乱码。想notepad++转换编码一样,亲测可用
批量获取关键字插件【适合采集来的文章后台批量获取】 本代码修改自5.0批量获取...共增加了4个文件,修改了一个文件,我打包发上来了,其中修改的文件时e/admin/adminstyle/1/menu/other.php,自己比对就不贴过程了。