2011-10-31 5 views

答えて

2

次のクラスを使用して、デバイス内のすべてのイメージを探します。最初に、文字列に値を与えずに関数を呼び出します。checkImages("");

public void checkImages(String imagePath) { 
    String path = ""; 
    if (imagePath.equals("")) 
     path = "file:///SDCard/"; 
    else 
     path = imagePath; 
    try { 
     FileConnection fileConnection = (FileConnection)Connector.open(path); 
     if (fileConnection.isDirectory()) { 
      Enumeration directoryEnumerator = fileConnection.list("*", true); 
      Vector contentVector = new Vector(); 
      while(directoryEnumerator.hasMoreElements()) { 
       contentVector.addElement(directoryEnumerator.nextElement()); 
      } 
      fileConnection.close(); 
      for (int i = 0 ; i < contentVector.size() ; i ++) { 
       String name = (String) contentVector.elementAt(i); 
       checkImages(path + name); 
      } 
     } 
     else { 
      if (path.toLowerCase().endsWith(".jpg")) { 
       imm.addElement(path); // your Vector 
       fileConnection.close(); 
      } 
     } 
    } catch (Exception ex) { } 
} 
+0

jpgファイルの場合、コードは閉じられていない 'FileConnection'インスタンスを残します。 –

+0

あなたは正しいです、私はそれを修正しました –

関連する問題