2012-07-13 6 views
0

로컬 폴더 파일의 lastmodifeddate를 FTP 파일의 lastmodifieddate로 설정하려고했습니다. 그러나 반환 값에서 false를 반환하고 date도 올바르게 설정되지 않습니다. 여기 Java에서 lastmodifieddate 설정 오류가 발생했습니다.

public static void getModifiedDateAndTimeFromFTPFile(String FTPHost, String FTPUserName, String FTPPassword, String FTPRemoteDirectory, String localFilePath, String fileName) { 
     try{ 
      //get Local File 
      File fileLocal = new File(localFilePath + fileName); 

      //Connect to FTP and get the lastmodified time of File. 
      FTPClient client = new FTPClient(); 
      client.connect(FTPHost); 
      client.login(FTPUserName, FTPPassword); 
      client.changeWorkingDirectory(FTPRemoteDirectory);   
      FTPFile ftpFile = client.listFiles(fileName)[0]; 

      //Get last_modified date of FTP file. 
      Date ftpFileDate = ftpFile.getTimestamp().getTime(); 

      //Now set date to the Local File. 
      boolean boolSetTime = fileLocal.setLastModified(ftpFileDate.getTime()); 
      System.out.println(" Was last modified time set successfully ? : " + boolSetTime);   
     } catch (Exception ex) { 
      System.out.println("Error : " + ex.toString()); 
     } 
    } 

이 사람이 내 실수를 지적으로 도와 줄 수, 기능인가?

감사

+0

ftpFileDate.getTime()을 에코 해 보셨습니까? 또한 해당 파일에 대한 사용 권한이 있습니까? –

+0

예 파일에 액세스 할 수있는 권한이 있습니다. 파일을 다운로드 할 수도 있습니다. –

+0

또한 ftpFileDate.getTime()을 인쇄하려고 시도했으며 정확한 lastmodifed 날짜를 반환합니다. –

답변

0

대부분의 아마 localFilePath + fileName는 의도 된 파일 이름을 형성하지 않습니다. 이 경우 File 객체를 생성 할 때 예외가 발생하지는 않지만 setLastModified(...)은 존재하지 않는 파일에서 항상 false를 반환합니다.

누락 된 경로 구분 기호 일 수 있습니까?

+0

해결책을 얻었습니다. 경로 구분 기호가 이유였습니다. 그렇지 않으면 기능이 좋았습니다. 제안에 감사드립니다. –

관련 문제