Skip to main content

Just another file copy program

There are two files in the project. and reads from properties file. In the properties file there are some configuration parameters. example:
sDirParam = /source
dDirParam = /destination
dFileExtParam = $G$
fileFilterParam = .srt;.avi;.pdf;
logFileParam = /logs/gates.log
import java.util.Properties;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;

public class gates {

static DateFormat df = new SimpleDateFormat ("dd.MM.yyyy  hh:mm:ss");
    public void wrLog(String file, String msg) {
        try {
            Date now = new Date();
            String currentTime = gates.df.format(now);
            FileWriter aWriter = new FileWriter(file, true);
            aWriter.write(currentTime + " " + msg + System.getProperty("line.separator"));
        catch (Exception e) {
public String[] getFileList(String dir, String extFilter) {
File directory = new File(dir);
final String[] okFileExtensions ;
String delimiter = ";";
okFileExtensions  = extFilter.split(delimiter);
if (!directory.isDirectory()) {
System.out.println("No directory provided!!!");
    return null;
FilenameFilter filefilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
for (String ext : okFileExtensions) {
if (name.endsWith(ext))
return true;
return false;
String[] filenames = directory.list(filefilter);
return filenames;
public static void main(String[] args) throws IOException {
Properties props = new Properties();
InputStream in = gates.class.getClassLoader().getResourceAsStream("");
String sDir = props.getProperty("sDirParam");
String dDir = props.getProperty("dDirParam");
String dFileExt = props.getProperty("dFileExtParam");
String allowedExt = props.getProperty("fileFilterParam");
String logFile = props.getProperty("logFileParam");
gates movePicture = new gates();
movePicture.wrLog(logFile, "gates LOG file: ");
String[] fileList = movePicture.getFileList(sDir,allowedExt);
for (String sFileName : fileList) {
int dotPos = sFileName.lastIndexOf(".");
String sFileNameWithoutExt = sFileName.substring(0, dotPos);
String dFileNameTemp = sFileNameWithoutExt + "." + dFileExt;
String dFileName = sFileName;
File sFile = new File(sDir + "/" + sFileName);
File dFileTemp = new File(dDir + "/" + dFileNameTemp);
File dFile = new File(dDir + "/" + dFileName);
movePicture.wrLog(logFile, "Source file does not exist!!! " + sDir + "/" + sFileName);
try {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sFile), 4096);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dFileTemp), 4096);
int theChar;
          while ((theChar = != -1) {
        movePicture.wrLog(logFile, "Copy done " + sFileName);
} catch (Exception ex) {
boolean ren = dFileTemp.renameTo(dFile);
if(!ren) {
movePicture.wrLog(logFile, "FileExtension failed to change!!! " + dDir + "/" + dFileNameTemp);
else {
movePicture.wrLog(logFile, "FileExtension changed successfully " + dDir + "/" + dFileName);
boolean  del = sFile.delete();
if (!del) {
movePicture.wrLog(logFile, "Source file deletion failed!!! " + sDir + "/" + sFileName);
else {
movePicture.wrLog(logFile, "Source file deleted successfully " + sDir + "/" + sFileName);


Popular posts from this blog

Creating Multiple VLANs over Bonding Interfaces with Proper Routing on a Centos Linux Host

In this post, I am going to explain configuring multiple VLANs on a bond interface. First and foremost, I would like to describe the environment and give details of the infrastructure. The server has 4 Ethernet links to a layer 3 switch with names: enp3s0f0, enp3s0f1, enp4s0f0, enp4s0f1 There are two bond interfaces both configured as active-backup bond0, bond1 enp4s0f0 and enp4s0f1 interfaces are bonded as bond0. Bond0 is for making ssh connections and management only so corresponding switch ports are not configured in trunk mode. enp3s0f0 and enp3s0f1 interfaces are bonded as bond1. Bond1 is for data and corresponding switch ports are configured in trunk mode. Bond0 is the default gateway for the server and has IP address Bond1 has three subinterfaces with VLAN 4, 36, 41. IP addresses are,, respectively. Proper communication with other servers on the network we should use routing tables. There are three

Listing Zimbra Accounts with Some Details

Recently I have to export the user list for a particular domain. Luckily Zimbra has Admin GUI with a search feature. When you search accounts, you can download search results as a comma-separated csv file. So I did a search and download the result file, but the result did not have all the columns I need and also there is no option for customizing columns for search results. So I had to write a bash script to get the desired list. Here is the bash script ( It can be customized by adding or removing field names. Run it under zimbra user like ./ <domain_name_here> ):