Skip to main content
prevent from error of null pointer
Source Link
Mimouni
  • 3.6k
  • 3
  • 32
  • 37

You could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles(); if(listOfFiles != null) {  for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName());   }  } } 

Do you want to only get JPEG files or all files?

You could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } } 

Do you want to only get JPEG files or all files?

You could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles(); if(listOfFiles != null) {  for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName());   }  } } 

Do you want to only get JPEG files or all files?

deleted 28 characters in body
Source Link
Andrei
  • 5.7k
  • 5
  • 27
  • 51

You could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles();  for (int i = 0; i < listOfFiles.length; i++) {   if (listOfFiles[i].isFile()) {   System.out.println("File " + listOfFiles[i].getName());   } else if (listOfFiles[i].isDirectory()) {   System.out.println("Directory " + listOfFiles[i].getName());   }  } 

Do you want to only get JPEG files or all files?

You could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles();  for (int i = 0; i < listOfFiles.length; i++) {   if (listOfFiles[i].isFile()) {   System.out.println("File " + listOfFiles[i].getName());   } else if (listOfFiles[i].isDirectory()) {   System.out.println("Directory " + listOfFiles[i].getName());   }  } 

Do you want to only get JPEG files or all files?

You could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } } 

Do you want to only get JPEG files or all files?

Removed ambiguous reference to C:\ directory in preamble which is not used in the code anymore
Source Link

For example for the C: directory youYou could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } } 

Do you want to only get JPEG files or all files?

For example for the C: directory you could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } } 

Do you want to only get JPEG files or all files?

You could do it like that:

File folder = new File("your/path"); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory " + listOfFiles[i].getName()); } } 

Do you want to only get JPEG files or all files?

added 6 characters in body
Source Link
RoflcoptrException
  • 52.3k
  • 35
  • 154
  • 200
Loading
Source Link
RoflcoptrException
  • 52.3k
  • 35
  • 154
  • 200
Loading