2017-09-22 2 views
-2

FTP 서버의 파일 이름을 파일하지만 같은 약간의 오차가 있습니다목록 내가 FTP 서버에있는 디렉토리에있는 파일을 나열 할

drwxrwxrwx 3 1004  1004   4096 Jan 17 2017 ftp 
Exception in thread "main" java.lang.NullPointerException 

내 코드 :

URL url = new URL("ftp://username:[email protected]:port"); 
URLConnection urlConnection = url.openConnection(); 
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); 
String inputLine; 
while ((inputLine = in.readLine()) != null){ 
    System.out.println(inputLine); 
} 

File cur = new File("/ftp/files/assignment/"); 
getAllFiles(cur);}} 
} 

public static void getAllFiles(File curDir){ 
    long len = 0; 
    long time = curDir.lastModified(); 
    File[] filesList = curDir.listFiles(); 
    for(File f : filesList){ 
     len += f.length(); 
     if(f.isDirectory()) 
     { 
      System.out.println(f.getName() + " " + len + " " + time); 
     } 
     if(f.isFile()){ 
      System.out.println(f.getName() + " " + len + " " + time); 
     } 
    } 
} 
+1

스택 트레이스 내 –

+0

스택 트레이스 – krismistri

+0

일반적으로 생산 목록 무엇인가를 추가하십시오 프로그램이 실행되고 예외가 발생합니다. –

답변

0

File로컬 파일에서만 작동하며 원격 FTP 서버의 파일은 작동하지 않으며 /ftp/files/assignment/은 로컬 컴퓨터에 존재하지 않습니다. 따라서 listFiles()은 for 루프가 중단되도록 null을 반환합니다. https://docs.oracle.com/javase/7/docs/api/java/io/File.html#listFiles()에서

- "반환 널 (null)이 추상 패스는 디렉토리를 나타내지 않는, 또는 I/O 오류가 발생하는 경우 경우."