Java Reference
In-Depth Information
public class FileCopierJMXImpl implements FileCopier {
public void copyFile(String srcDir, String destDir, String filename)
throws IOException {
File srcFile = new File(srcDir, filename);
File destFile = new File(destDir, filename);
FileCopyUtils.copy(srcFile, destFile);
With the help of a file copier, you can implement your file replicator, as shown following. Each time
you call the replicate() method, all files in the source directory will be replicated to the destination
directory. To avoid unexpected problems caused by concurrent replication, you declare this method as
synchronized .
package com.apress.springenterpriserecipes.replicator;
public class FileReplicatorImpl implements FileReplicator {
private String srcDir;
private String destDir;
private FileCopier fileCopier;
// accessors …
// mutators …
public void setSrcDir(String srcDir) {
this.srcDir = srcDir;
public void setDestDir(String destDir) {
this.destDir = destDir;
public void setFileCopier(FileCopier fileCopier) {
this.fileCopier = fileCopier;
public synchronized void replicate() throws IOException {
File[] files = new File(srcDir).listFiles();
for (File file : files) {
if (file.isFile()) {
fileCopier.copyFile(srcDir, destDir, file.getName());
Search WWH ::

Custom Search