MyTetra Share
Делитесь знаниями!
Listing Directories
Время создания: 05.09.2017 11:15
Текстовые метки: code
Раздел: Java - Tutorial - Directories
Запись: xintrea/mytetra_db_mcold/master/base/15045979066hyj6catcz/text.html на raw.githubusercontent.com

Listing Directories

You can use list( ) method provided by File object to list down all the files and directories available in a directory as follows −

Example

import java.io.File;
public class ReadDir {

   public static void main(String[] args) {
      File file = null;
      String[] paths;
  
      try {      
         // create new file object
         file = new File("/tmp");

         // array of files and directory
         paths = file.list();

         // for each name in the path array
         for(String path:paths) {
            // prints filename and directory name
            System.out.println(path);
         }
      }catch(Exception e) {
         // if any error occurs
         e.printStackTrace();
      }
   }
}

This will produce the following result based on the directories and files available in your /tmp directory −

Output

test1.txt
test2.txt
ReadDir.java
ReadDir.class
Так же в этом разделе:
 
MyTetra Share v.0.58
Яндекс индекс цитирования