java复制目录工具类

public void copyDirectory(String file1,String file2)throws IOException {
		if (!new File(file2).exists()) {
			new File(file2).mkdirs();
			File[] files=new File(file1).listFiles();
			for (int i = 0; i < files.length; i++) {
				System.out.println(files[1].getName());
				if (files[i].isFile()) {
					FileInputStream inputStream =new FileInputStream(files[i]);
					FileOutputStream outputStream =new FileOutputStream(file2+"/"+files[i].getName());
					byte[] b=new byte[1024*5];
					int len;
					while ((len=inputStream.read(b))!=-1) {
						outputStream.write(b, 0, len);
					}
					outputStream.flush();
					outputStream.close();
					inputStream.close();
				}
				if (files[i].isDirectory()) {
					copyDirectory(file1+"/"+files[i].getName(), file2+"/"+files[i].getName());
				}
			}
		}
	}
}

你可能感兴趣的:(java,String,File,工具,byte)