khaleel. Powered by Blogger.
Showing posts with label File Operations. Show all posts
Showing posts with label File Operations. Show all posts

Copying from one directory to another directory, Also deleting files from a directory

Tuesday, 31 May 2011


import java.io.File;
import java.io.IOException;
import java.util.Calendar;

import org.apache.commons.io.FileUtils;

public class FileOperations {
public void copy_Directory_Files(){
    System.out.println("----u r in copy_directory==========");
    String[] monthName = {"January", "February",
            "March", "April", "May", "June", "July",
            "August", "September", "October", "November",
    "December"};
    Calendar cal = Calendar.getInstance();
    String monthSalary = monthName[(cal.get(Calendar.MONTH)-1)];
    int yearSalary = cal.get(Calendar.YEAR);
    String savefile=JPropertyReader.readProperty("savefile");
    File srcDir = new File(savefile);
    File srcDir1 = new File(JPropertyReader.readProperty("pdffiles"));
    String archivedraftfiles=JPropertyReader.readProperty("archivefiles")+monthSalary+yearSalary+JPropertyReader.readProperty("archivedrafts");
    String archievepdffiles=JPropertyReader.readProperty("archivefiles")+monthSalary+yearSalary+JPropertyReader.readProperty("archivepdffiles");
    File trgDir = new File(archivedraftfiles);
    File trgDir1 = new File(archievepdffiles);
    //boolean success=true;
    try {
            FileUtils.copyDirectory(srcDir, trgDir);
            FileUtils.copyDirectory(srcDir1, trgDir1);
        } catch (IOException e) {
        e.printStackTrace();
    }
   
}
public static boolean delete_Files(){
    boolean t=true;
    String savefile=JPropertyReader.readProperty("savefile");
    String pdffiles=JPropertyReader.readProperty("pdffiles");
    File directory = new File(savefile);
    File[] files = directory.listFiles();
    for (File file : files)    {
        if (!file.delete())
        {
            t=false;
        }
    }
    File directory1 = new File(pdffiles);
    File[] files1 = directory1.listFiles();
    for (File file : files1)    {
        if (!file.delete())
        {
            t=false;
        }
    }
    return t;
  }   
}
jproperty Reader class


import java.util.ResourceBundle;
public class JPropertyReader {
    public static String readProperty(String key) {
        String PROPERTY_FILE=MessageConstants.prop_dir;
        ResourceBundle rb = ResourceBundle.getBundle(PROPERTY_FILE);
        String propvalue=rb.getString(key);
        return propvalue;
    }
    public static String  readlog4JProperty(String strKey)
    {    String PROPERTY_NAME="ATR";
        ResourceBundle rb=ResourceBundle.getBundle(PROPERTY_NAME);
        String strPropertyValue=rb.getString(strKey);
        return strPropertyValue;
    }
}
ATR.Properties file 
#Authentication details
username=centris
password=centris


#validation details
user_req=<br><font color=#FFCC00> * <b>Username is required</b></font>
pwd_req=<br><font color=#FFCC00>  * <b>Password is required</b></font>

#file constants
savefile=D:/Drafts/
pdffiles=D:/Payslips/
archivefiles=D:/archive/
archivedrafts=/Drafts/
archivepdffiles=/Payslips/
csvfile=D:/Drafts/payslip.csv

FROM_ADDRESS=venkatesh.s@centrisinfotech.com
SENDER_PASSWORD=ven123$


#image constants
logo_img=/ATR/images/centrislogo.png
pdflogo_img=http://localhost:8080/ATR/images/centrislogo.png
home_img=/ATR/images/home.jpg
upload_img=/ATR/images/upload.jpg
pdfgen_img=/ATR/images/createpdf.png
sendmail_img=/ATR/images/emaillaw.jpg
logout_img=/ATR/images/log.gif
back_img=/ATR/images/back.png
audit_img=/ATR/images/audit.jpg
#Property file location details
prop_dir=ATR

ATR_LOG_PATH=D\:/ATRLogs/ss
LOG4J_PATH=D\:/Tomcat 5.5/webapps/ATR/WEB-INF/classes/log4j.properties

# Resources for parameter 'com.centris.struts.ATR'
# Project ATR

Read more...
Related Posts Plugin for WordPress, Blogger...
Promote Your Blog

About This Blog

This blog is for java lovers

Total Pageviews

About Me

khaleel-bapatla
BAPATLA, ap, India
simple and honest
View my complete profile

  © Blogger template On The Road by Ourblogtemplates.com 2009

Back to TOP