Android 项目编码转换
来源:互联网 发布:淘宝上架数量限制 编辑:程序博客网 时间:2024/05/24 01:10
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* 主要实现将制定文件夹下的所有文本文件保存到UTF-8的文本编码
*
* @author Rainbow
*
*/
public class ProjectCopyWithTextEncoder {
//目标路径
private static final String destDir = "F:"+File.separator ;
public static void main(String[] args) {
query(new File ("E:\\Android Catogorywc\\android_98player1.0\\App98playerUser5")) ;
}
/**
* 将指定的文本保存到指定的编码格式中
* @param resFile 源文件实例
* @param destFile 目标位置
*/
private static void toUtf8TextFile(File resFile , File destFile) {
try {
FileInputStream fis = new FileInputStream(resFile);
InputStreamReader isr = new InputStreamReader(fis , "GBK");
FileOutputStream fos = new FileOutputStream(destFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");//
int s;
while ((s = isr.read()) != -1) {
osw.write(s);
}
osw.flush();
osw.close();
isr.close();
System.out.println("从"+resFile.getParent()+" 拷贝到 :"+destFile.getPath());
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 传入指定文件目录
* @param file
*/
private static void query (File file) {
if(file.isDirectory()) {
File[] files = file.listFiles() ;
int len = files.length ;
for (int i = 0 ; i < len ; i ++) {
if(files[i].isDirectory()) {
query( files[i] );
} else {
doWorkFile(files[i]) ;
}
}
} else {
doWorkFile(file) ;
}
}
/**
* 只针对java文件和xml文件
* @param file
*/
private static void doWorkFile (File file) {
File dir = new File(destDir + filterPackage(file)) ;
if(!dir.exists()) {
dir.mkdirs() ;
System.out.println("create folder : "+dir.getPath());
}
if(file.getPath().endsWith(".java") || file.getPath().endsWith(".xml")) {
toUtf8TextFile(file , new File(dir, file.getName())) ;
} else {
copyUniversalFile(file , new File(dir, file.getName())) ;
}
}
private static void copyUniversalFile (File resFile , File destFile) {
try {
FileInputStream fin = new FileInputStream(resFile);
byte data[] = new byte[fin.available()];
FileOutputStream fout = new FileOutputStream(destFile) ;
fout.write(data) ;
fout.flush() ;
fout.close() ;
fin.close() ;
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 筛选出包
*/
public static String filterPackage (File file) {
return file.getParentFile().getPath().split(":")[1] ;
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* 主要实现将制定文件夹下的所有文本文件保存到UTF-8的文本编码
*
* @author Rainbow
*
*/
public class ProjectCopyWithTextEncoder {
//目标路径
private static final String destDir = "F:"+File.separator ;
public static void main(String[] args) {
query(new File ("E:\\Android Catogorywc\\android_98player1.0\\App98playerUser5")) ;
}
/**
* 将指定的文本保存到指定的编码格式中
* @param resFile 源文件实例
* @param destFile 目标位置
*/
private static void toUtf8TextFile(File resFile , File destFile) {
try {
FileInputStream fis = new FileInputStream(resFile);
InputStreamReader isr = new InputStreamReader(fis , "GBK");
FileOutputStream fos = new FileOutputStream(destFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");//
int s;
while ((s = isr.read()) != -1) {
osw.write(s);
}
osw.flush();
osw.close();
isr.close();
System.out.println("从"+resFile.getParent()+" 拷贝到 :"+destFile.getPath());
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 传入指定文件目录
* @param file
*/
private static void query (File file) {
if(file.isDirectory()) {
File[] files = file.listFiles() ;
int len = files.length ;
for (int i = 0 ; i < len ; i ++) {
if(files[i].isDirectory()) {
query( files[i] );
} else {
doWorkFile(files[i]) ;
}
}
} else {
doWorkFile(file) ;
}
}
/**
* 只针对java文件和xml文件
* @param file
*/
private static void doWorkFile (File file) {
File dir = new File(destDir + filterPackage(file)) ;
if(!dir.exists()) {
dir.mkdirs() ;
System.out.println("create folder : "+dir.getPath());
}
if(file.getPath().endsWith(".java") || file.getPath().endsWith(".xml")) {
toUtf8TextFile(file , new File(dir, file.getName())) ;
} else {
copyUniversalFile(file , new File(dir, file.getName())) ;
}
}
private static void copyUniversalFile (File resFile , File destFile) {
try {
FileInputStream fin = new FileInputStream(resFile);
byte data[] = new byte[fin.available()];
FileOutputStream fout = new FileOutputStream(destFile) ;
fout.write(data) ;
fout.flush() ;
fout.close() ;
fin.close() ;
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 筛选出包
*/
public static String filterPackage (File file) {
return file.getParentFile().getPath().split(":")[1] ;
}
}
0 0
- Android 项目编码转换
- android 字符编码转换
- Eclipse项目GBK编码转换
- 项目编码批量转换工具
- android 项目编码修改, GBK 变UTF-8(进阶版) 编码转换 项目代码转换 转utf-8 转换utf-8
- Android项目编码规范
- Unity项目脚本编码格式转换为UTF8编码格式
- Android项目及编码规则
- android studio 设置项目编码
- Android Studio NDK 代码 Source Insight调试 (NDK 目前开发方案 | NDK 编译 | 导入 so 库 | 项目编码转换)
- android 使用icon进行字符编码转换
- 转战Android之NDK编码转换
- Android NDK使用Iconv进行编码转换
- Android代码编码格式的转换
- Android Studio项目转换成eclipse项目
- Eclipse中项目编码格式转换(转码)
- Android项目中Eclipse编码设置
- android studio 项目编码格式的设置
- js json回车 处理特殊字符,textArea 换行处理
- Ultraedit 中文显示乱码
- Mac自己创建打开终端快捷键(任意软件)
- ListView在下拉时出现空指针错误
- Android程序关闭时提示:“### WARNING: SD Card files must be at least 9MB,...”
- Android 项目编码转换
- cygwin 下安装python MySQLdb
- linx3.0.101下面DS1307 RTC驱动调试过程
- 16.从小到大排列三个数
- MFC+OpenCV Debug正常Release模式下内存错误
- Spring4+Hibernate4配置注解事务控制
- ios7和ios8下通过表格中的btn获取当前行数
- 遍历NSData的方法
- python nose框架--setup/teardown