public class FileDemo {
   public static void main(String[] args) {      
      File f = null;
      File[] paths;
      
      try {  
      
         // create new file
         f = new File("c:/test");
         
         // returns pathnames for files and directory
         paths = f.listFiles();
         
         // for each pathname in pathname array
         for(File path:paths) {
         
            // prints file and directory paths
            System.out.println(path);
         }
         
      } catch(Exception e) {
         // if any error occurs
         e.printStackTrace();
      }
   }
}

        

public class solution { 
	public static void main(String args[]) 
	{ 

		// try-catch block to handle exceptions 
		try { 

			// Create a file object 
			File f = new File("f:\\program"); 

			// Get all the names of the files present 
			// in the given directory 
			File[] files = f.listFiles(); 

			System.out.println("Files are:"); 

			// Display the names of the files 
			for (int i = 0; i < files.length; i++) { 
				System.out.println(files[i].getName()); 
			} 
		} 
		catch (Exception e) { 
			System.err.println(e.getMessage()); 
		} 
	} 
} 

        

public class FileListFilesExample {

	public static void main(String[] args) {

		// initialize File object
		File file = new File("C:\\javatutorialhq");

		// check if the specified pathname is directory first
		if(file.isDirectory()){
			//list all files on directory
			File[] files = file.listFiles();
			for(File f:files){
				try {
					System.out.println(f.getCanonicalPath());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}

        

public class listFilesExample { // public class FileExample {
 
	public static void main(String[] args) throws Exception {
 
		File file = null;
		File[] paths;
 
		try {
 
			file = new File("c:\sandbox");
 
			// list of file objects
			paths = file.listFiles();
 
			// for each name in the path array
			for (File path : paths) {
				// prints file name or directory name
				if (path.isDirectory()) {
					System.out.println("Directory " + path);
				} else {
					System.out.println("File " + path);
				}
			}
 
		} catch (Exception e) {
			System.err.println("Things went wrong: " + e.getMessage());
			e.printStackTrace();
		}
	}
}

        

public class App {
 
    public static void main(String[] args) {
 
        File directory = new File("C:\\technicalkeeda");
 
        File[] files = directory.listFiles();
        for (File file: files) {
            try {
 
                System.out.println(file.getCanonicalPath());
 
            } catch (IOException e) {
                e.printStackTrace();
 
            }
        }
    }
}

        

public Collection<String> getEtr(){
	Collection<File> res = new LinkedList<File>();
	File[] listdir = new File(Engine.PROJECTS_PATH).listFiles();
	for(File s : listdir){
		File tracedir = new File(s,"Traces");
		if(tracedir.exists()&&tracedir.isDirectory()){
			File[] listconnectors = tracedir.listFiles();
			for(File s2 : listconnectors){
				res.addAll(Arrays.asList(s2.listFiles(new FilenameFilter(){
					public boolean accept(File arg0, String arg1) {
						return arg1.endsWith(".etr");
					}
				})));
			}
		}
	}
	Collection<String> listetr = new ArrayList<String>(res.size());
	for(File f : res)
		listetr.add(f.getPath().substring(Engine.PROJECTS_PATH.length()));
	return listetr;
}

        

public static long getFolderSize(File file) throws Exception {
  long size = 0;
  try {
    File[] fileList = file.listFiles();
    for (int i = 0; i < fileList.length; i++) {
      if (fileList[i].isDirectory()) {
        size = size + getFolderSize(fileList[i]);
      } else {
        size = size + fileList[i].length();
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return size;
}

        

private void run(final String prefix, final MessageDigest messageDigest) throws IOException {
    if (inputs == null) {
        println(prefix, DigestUtils.digest(messageDigest, System.in));
        return;
    }
    for(final String source : inputs) {
        final File file = new File(source);
        if (file.isFile()) {
            println(prefix, DigestUtils.digest(messageDigest, file), source);
        } else if (file.isDirectory()) {
            final File[] listFiles = file.listFiles();
            if (listFiles != null) {
                run(prefix, messageDigest, listFiles);
            }
        } else {
            // use the default charset for the command-line parameter
            final byte[] bytes = source.getBytes(Charset.defaultCharset());
            println(prefix, DigestUtils.digest(messageDigest, bytes));
        }
    }
}

        

protected List<File> findJarFile(String scriptLibDir) {
	List<File> files = new ArrayList<File>();
	try {
		File file = new File(scriptLibDir);
		if (file.isDirectory()) {
			for (File f : file.listFiles()) {
				if (f.isFile() && f.getName().endsWith(".jar")) {
					files.add(f);
				}
			}
		}
	} catch (Exception e) {
		_log.error(e.getMessage(), e);
	}
	return files;
}

        

public static long getFolderSize(File dir) {
    if (dir.exists()) {
        long result = 0;
        File[] fileList = dir.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            // Recursive call if it's a directory
            if (fileList[i].isDirectory()) {
                result += getFolderSize(fileList[i]);
            } else {
                // Sum the file size in bytes
                result += fileList[i].length();
            }
        }
        return result; // return the file size
    }
    return 0;
}        
main