一,复制文件
File oldFile = new File("F:/FavoriteVideo/0CAMGLN0K.jpg");
File newFile = new File("F:/FavoriteVideo/yang.jpg");
if(!oldFile.exists()){
newFile.createNewFile();
}
FileInputStream input = new FileInputStream(oldFile);
/*如果你想让文件的复制加快BufferedInputStream bufferedInput = new BufferedInputStream(input);*/
FileOutputStream output = new FileOutputStream(newFile );
/*BufferedOutputStream bufferedOut = new BufferedOutputStream(output);*/
byte[] buffer = new byte[512];
int b = 0;
long startTime = System.currentTimeMillis();
while(b!=-1){
b=input.read(buffer);
output.write(buffer, 0, buffer.length);
}
long endTime = System.currentTimeMillis();
System.out.println(endTime-startTime);
input.close();
output.flush();
output.close();
二文件的查询方法
public class ShowFilePath {
public void show(String path){
File f = new File(path);
if(f.isFile()){
System.out.println(f.getPath());
}else if(f.isDirectory()){
File[] files = f.listFiles();
if(files!=null){
for(File file:files ){
if(file.isFile()){
System.out.println(file.getPath());
}else {
System.out.println("["+file.getPath()+"]");
show(file.getPath());
}
}
}
}
}