-1

Hi I need to copy the files stored in an array to a folder in the destination using java 7 copyfilemethod. I donot get any error, but it doesnt copies the files.Please help to copy the files from source to destination folder.Thanks in advance public class copyFiles {

public static void main(String[] args) {
Date date = new Date(); // your date
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);
    int day = cal.get(Calendar.DAY_OF_MONTH);
    String date2 = ((month+1) + "/" + (day) + "/" + year);
    System.out.println("the current date is " + date2);
    String path = "c://Users//Desktop//Test";
      System.out.println("PATH::"+path);

    File directory = new File(path);
    File[] myarray;
    myarray = directory.listFiles();
    try{
    for (int j = 0; j < myarray.length; j++) {
    if(myarray[j].isDirectory()){
    SimpleDateFormat sdf = new SimpleDateFormat("M/D/YY");
    String dt = sdf.format(myarray[j].lastmodified());
    if(dt.compareTo(date2) == 0){
    File[] myarray1 - myarray[j].listFiles();
    for(int i = 0; i < myarray1,length; i++){
    if(myarray1[i].isDirectory()){
    System.out.println("Do nothing");
    }
    else
    {
    SimpleDateFormat sdf1 = new SimpleDateFormat("M/D/YYYY");
    String dt1 = sdf1.format(myarray1[i].lastmodified());
    if(dt1.compareTo(date2) == 0){
    System.out.println(myarray1[i]);
    File Source = myarray1[i];
    File Dest = new File("c://Users//Desktop//destination");
    CopyFileusingJava7Files(source, dest);

    }

    }
    }
    }
    }
    }
    }
    catch(Exception e){

    System.out.println("The file is not found");
    }
    }
    Private Static void CopyFileusingJava7Files(File source, File dest) throws IOException{
    Files.copy(source.toPath(), dest.toPath());
    }}
kiran
  • 1
  • 1

1 Answers1

0

Try it with administration rights. Normally a JAR doesn't have that much rights unless you define the rights you need.

I'll share some intresting links below where you can find information about defineing permissions. This is possible with a file: "MANIFEST.MF".

Manifest Basics

Defining Permissions in the mainfest

Casper
  • 293
  • 2
  • 22