2016-07-05 1 views
-5

그래서 "c : /"에 "Diretorio"라는 폴더가 있고 그 안에 폴더가 있고 그 안에 폴더가 더 있습니다 (C :/Diretorio/Antonio/Documentos/온도)가, 그리고의 JList에 난 shearch [이 경로이다] 난이 시작할 때의 JList에 표시하는 코드를 만들었다 :Jlsit, 가장 큰 항목을 결정

C : \ Diretorio \ 안토니오

C : \ Diretorio \ Antonio \ Documentos

C : \ Diretorio \ Antonio \ Documentos \ Temp

내 질문은, 어떻게 든 그냥 "C : \ Diretorio \ Antonio \ Documentos \ Temp"jlist 항목에 나타날 수 있습니까?

--------------- 코드 -------------------

public teste_borrar2() throws IOException { 
     super(new BorderLayout()); 

     File raiz = new File("C:\\Diretorio\\"); 


     listModel = new DefaultListModel(); 
     listModel = displayDirectoryContents(raiz); 
} 


public static DefaultListModel displayDirectoryContents(File dir) { 
     File[] files = dir.listFiles(); 
     for (File file : files) { 
      if (file.isDirectory()){ 

       System.out.println("Directory Name==>:" + file); 

       displayDirectoryContents(file); 
       listModel.addElement(file); 

      } 
      } 
     return listModel; 

    } 
+1

귀하의 질문은 매우 명확하지 않습니다. – explv

+0

구체적인 문제를 명확히하거나 추가 정보를 추가하여 필요한 것을 정확하게 강조하십시오. 현재 작성된 내용이므로 귀하가 원하는 내용을 정확하게 말하기는 어렵습니다. – abarisone

+1

"가장 큰 것"에 비해 무엇? 경로 길이? 디렉토리 크기? – Tom

답변

0

내가부터 알고있는 것처럼 귀하의 의견, 당신은 단지 Strings로 대표되는 pathes의 긴 찾을 수 있습니다. 다음과 같이 할 수 있습니다.

String[] pathes = new String[3]; 
//add your pathes to array here 
String longestString = ""; 
for(int i = 0; i < pathes.length; i++) { 
    if (pathes[i].length() > longestString.length()) { 
     longestString = pathes[i] 
    } 
} 
//add longestPath to your JList 
관련 문제