JAVA文件操作总结
File类
File f = new File(path);
path为实际路径,该路径可以是文件,或文件夹,也可以是不存在的。
f.exists() 可以判断该路是否存在。
f.isDirectory() 可以判断是否是文件夹。
f.mkdirs(); 递归创建文件夹
File和输入输出流之间纽带FileInutStream,FileOutputStream
URL url = new URL(strUrl);
BufferedInputStream bis = new BufferedInputStream(url.openStream()); //用buffer
OutputStream os = new FileOutputStream(new File(path + newName));
byte[] bytes = new byte[1024];
int len;
while((len = bis.read(bytes)) > 0) { //循环读取1024字节
os.write(bytes, 0, len); //写入1024字节
}
bis.close();
os.flush();
os.close();