public class GBKForUTF8 {
public static final List
/**
- @param inEncoding 原编码格式
- @param outEncoding 目标编码格式
- @param inFileName 原文件路径
- @param outFileName 目标文件路径
- @throws IOException
*/
public static void changeEncoding(String inEncoding, String outEncoding, String inFileName, String outFileName)
throws IOException {
File file = new File(outFileName);
if(!file.exists()){
file.createNewFile();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inFileName), inEncoding));
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(outFileName), outEncoding));
String line = null;
while ((line = reader.readLine()) != null) {
writer.write(line, 0, line.length());
writer.newLine();
}
writer.flush();
writer.close();
reader.close();
}
/**
- @decription 将根目录下所有文件列出
- @param path 原根目录路径
*/
public static void getFilePath(String path) {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
if(files[i].isFile()){
filePathLists.add(files[i].getAbsolutePath());
}
if(files[i].isDirectory()){
getFilePath(files[i].getAbsolutePath());
}
}
}
}
/**
- @description 创建目标文件夹下不存在的文件
- @param path 单个文件路径
- @throws IOException
*/
public static void createFile(String path) throws IOException{
String[] paths = path.split(“\\“);
String str = paths[0];
for(int i = 1; i < paths.length; i++){
str += “\“ + paths[i];
File file = new File(str);
if(!file.exists()){
if(i == paths.length - 1){
file.createNewFile();
}else{
file.mkdir();
}
}
}
}