IO流:
解决读文件后中文乱码问题(在inputstream中设置读取文件的格式)
FileInputStream fis = new FileInputStream(new File("E:/战网/Hearthstone/Strings/zhCN/CREDITS_2014.txt"));
InputStreamReader is = new InputStreamReader(fis, "utf-8");
BufferedReader br = new BufferedReader(is);
String s = null;
while((s = br.readLine())!= null){
System.out.println(s);
}
采用缓冲数组读取文件提高效率
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
String path));
File descFile = new File("F://1.avi");
FileOutputStream fos = new FileOutputStream(descFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(descFile));
BufferedWriter bw = new
long before = System.currentTimeMillis();
byte[] b = new byte[1024*3];
int hasRead = 0;
while((hasRead = bis.read(b))!= -1){
bos.write(b, 0, hasRead);
bos.flush();
}
复制一个文件夹
public static void copyFolder(File srcFile, File destFile) {
File[] files = srcFile.listFiles();
for (File f : files) {
if (f.isDirectory()) {
//File类的构造函数(destFile是f.getName()的上一级目录)
File toFile = new File(destFile,f.getName());
toFile.mkdirs();
copyFolder(f, toFile);
} else {
File toFile = new File(destFile, f.getName());
copyFile(f, toFile);
}
}
}