刚写了一个关于复制单级文件夹内容的代码,然后需求用UTF-8的数据类型完成,有没有大神指导怎么将GBK改为UIT-8的数据操作啊:Q
public class Test3 {
public static void main(String[] args) throws IOException {
File srcDir = new File("src");
File destDir = new File("abc");
method(srcDir,destDir);
}
public static void method(File src,File dest) throws IOException{
File[] list = src.listFiles();
for (File fileorDir : list) {
if(fileorDir.isDirectory()) {
File oldDir = fileorDir;
File newDir = new File(dest,oldDir.getName());
newDir.mkdir();
method(oldDir,newDir);
} else {
File oldFile = fileorDir;
File newFile = new File(dest,oldFile.getName());
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(oldFile));
BufferedOutputStream bos = new BufferedOutputStream(newFileOutputStream(newFile));
byte[] bytes = new byte[1024];
int len;
while((len=bis.read(bytes))!=-1) {
bos.write(bytes, 0, len);
}
bos.close();
bis.close();
}
}
}
}
|
|