Computer Science, asked by aravind1999ram, 2 months ago

// Missing Statement
For(int i=0;i< dirs.length; i++)
System.out.println("Root[*+j+") : " + dirs[i]);​

Answers

Answered by ravilaccs
1

Answer:

Use listRoots() of File class to find all root directories.

Explanation:

Given: Piece of java code

Find: Missing of statement

Step 1:

Method 1:

import java.io.*;

public class GeeksforGeeks {

   public static void main(String[] args)

   {

       File[] rDirs = File.listRoots();

       for (int i = 0; i < rDirs.length; i++)

           System.out.println(rDirs[i].toString());        

   }

}

Method 2:

To solve your issue with the TestX folders, First iterate through the list of folders:

File[] dirs = new File(".").listFiles(new WildcardFileFilter("Test*.java");

for (int i=0; i<dirs.length; i++) {

  File dir = dirs[i];

  if (dir.isDirectory()) {

      File[] files = dir.listFiles(new WildcardFileFilter("sample*.java"));

  }

}

Answered by anjaliom1122
0

Answer:

Use listRoots() of File class to find all root directories.

Explanation:

import java.io.*;

public class anj {

  public static void main(String[] args)

  {

      File[] rDirs = File.listRoots();

      for (int i = 0; i < rDirs.length; i++)

          System.out.println(rDirs[i].toString());        

  }

}

To solve your issue with the TestX folders, First iterate through the list of folders:

File[] dirs = new File(".").listFiles(new WildcardFileFilter("Test*.java");

for (int i=0; i<dirs.length; i++) {

 File dir = dirs[i];

 if (dir.isDirectory()) {

     File[] files = dir.listFiles(new WildcardFileFilter("sample*.java"));

 }

}

Similar questions