2017-03-05 116 views
0

我有一堆根據詩人的名字進行分類的文件夾,這些文件夾內部是由詩歌標題命名的JSON文件。 那麼如何從應用程序瀏覽這些文件。 作家的數量和詩歌的數量太多,我不知道有多少詩是在那裏。我想先打電話給所有的詩人命名螞蟻然後標題。如何從android應用程序讀取json文件的名稱?

我想不出有什麼辦法試過這個。

館藏結構

所有的詩歌可以在相應的作者的子目錄的集合目錄中找到。

collection 
├── William Cowper 
│ └── Light Shining out of Darkness.json 
└── William Ernest Henley 
    └── Invictus.json 
+1

看一看[此](http://stackoverflow.com/questions/11194287/convert-a-directory-structure-in-the-filesystem-to-json-with-node -js) –

+0

謝謝你的幫助,但我希望有一些新手實現我不知道node.js –

回答

0
int Index = 0; // Global 
String[] FileDir; // Global 

// Start onCreate or some function 
File currentDir = new File(""); // collection directory as parameter 
DisplayFile(currentDir); 


public static void DisplayFile(File currentDir) 
{ 
    try { 

     File[] files = currentDir.listFiles(); 
     for (File file : files) { 

      if (file.isDirectory()) { 

       //System.out.println("directory:" + file.getCanonicalPath()); 
       DisplayFile(file); 

      } else { 
       if(file.getCanonicalFile().toString().contains(".json")) 
       FileDir[Index] = file.getCanonicalPath(); 
       Index++; 
      } 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 
相關問題