List of usage examples for java.io File list
public String[] list()
From source file:Main.java
public static void main(String[] args) { File file = new File("C:/"); String[] files = file.list(); System.out.println("contents of " + file.getPath()); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }//from w w w.jav a2 s . c om }
From source file:MainClass.java
public static void main(String[] a) { File myFile = new File("C:" + File.separator); for (String s : myFile.list()) { System.out.println(s);// ww w . j a va 2 s. c o m } }
From source file:Main.java
public static void main(String[] argv) throws Exception { File dir = new File("directoryName"); String[] children = dir.list(); if (children == null) { System.out.println("does not exist or is not a directory"); } else {//from w w w .j ava 2 s . co m for (int i = 0; i < children.length; i++) { String filename = children[i]; System.out.println(filename); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { CheckedOutputStream checksum = new CheckedOutputStream(new FileOutputStream("data.zip"), new Adler32()); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum)); int size = 0; byte[] buffer = new byte[1024]; File dir = new File("."); String[] files = dir.list(); for (int i = 0; i < files.length; i++) { System.out.println("Compressing: " + files[i]); FileInputStream fis = new FileInputStream(files[i]); ZipEntry zipEntry = new ZipEntry(files[i]); zos.putNextEntry(zipEntry);/* w w w . j a va 2s.co m*/ while ((size = fis.read(buffer, 0, buffer.length)) > 0) { zos.write(buffer, 0, size); } zos.closeEntry(); fis.close(); } zos.close(); System.out.println("Checksum : " + checksum.getChecksum().getValue()); }
From source file:Main.java
public static void main(String[] args) { File file = new File("/data"); if (file.isDirectory()) { String[] files = file.list(); if (files.length > 0) { System.out.println("The " + file.getPath() + " is not empty!"); }//from w w w. j a v a 2s .co m } }
From source file:Main.java
public static void main(String args[]) throws Exception { File file = new File("."); if (file.isDirectory()) { String[] files = file.list(); for (int i = 0; i < files.length; i++) System.out.println(files[i]); } else {/* w ww .j av a 2s .c o m*/ FileReader fr = new FileReader(file); BufferedReader in = new BufferedReader(fr); String line; while ((line = in.readLine()) != null) System.out.println(line); } }
From source file:Main.java
public static void main(String[] args) { // create new file File f = new File("c:/test"); // array of files and directory String[] paths = f.list(); // for each name in the path array for (String path : paths) { System.out.println(path); }// w w w . ja v a 2 s. c o m }
From source file:MainClass.java
public static void main(String[] args) { File path = new File("."); String[] list;//from w w w . j a v a2s . co m if (args.length == 0) list = path.list(); else list = path.list(new DirFilter(args[0])); Arrays.sort(list); for (int i = 0; i < list.length; i++) System.out.println(list[i]); }
From source file:MainClass.java
public static void main(final String[] args) { File path = new File("."); String[] list;// w ww . ja v a 2 s . c om if (args.length == 0) list = path.list(); else list = path.list(new FilenameFilter() { private Pattern pattern = Pattern.compile(args[0]); public boolean accept(File dir, String name) { return pattern.matcher(new File(name).getName()).matches(); } }); Arrays.sort(list); for (int i = 0; i < list.length; i++) System.out.println(list[i]); }
From source file:FindDirectories.java
public static void main(String[] args) { // if no arguments provided, start at the parent directory if (args.length == 0) args = new String[] { ".." }; try {// ww w . j ava 2 s . c om File pathName = new File(args[0]); String[] fileNames = pathName.list(); // enumerate all files in the directory for (int i = 0; i < fileNames.length; i++) { File f = new File(pathName.getPath(), fileNames[i]); // if the file is again a directory, call the main method recursively if (f.isDirectory()) { System.out.println(f.getCanonicalPath()); main(new String[] { f.getPath() }); } } } catch (IOException e) { e.printStackTrace(); } }