2017-03-09 4 views
-1

こんにちは私は、Java 7のcopyfilemethodを使用して、配列のファイルをコピー先のフォルダにコピーする必要があります。Java 7のコピーファイルメソッドを使用してフォルダにファイルをコピー

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()); 
    }} 

答えて

0

は、管理者権限でそれを試してみてください{私はエラーを取得するscroll down toパソコンへ転送、それdoesntのコピーfiles.Pleaseヘルプは、事前に目的地folder.Thanksにソースから パブリッククラスコピーファイルをファイルをコピーします。通常、JARには、必要な権限を定義しない限り、あまり多くの権利がありません。

ここでは、権限の定義に関する情報を見つけるためのリンクをご紹介します。これはファイル "MANIFEST.MF"で可能です。

Manifest Basics

Defining Permissions in the mainfest

関連する問題