List of usage examples for java.io File isFile
public boolean isFile()
From source file:Main.java
public static void main(String[] args) { // Change the dirPath value to list files from your directory String dirPath = "C:\\"; File dir = new File(dirPath); File[] list = dir.listFiles(); for (File f : list) { if (f.isFile()) { System.out.println(f.getPath() + " (File)"); } else if (f.isDirectory()) { System.out.println(f.getPath() + " (Directory)"); }/*w w w . j a va 2s. co m*/ } }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test"); FileFilter filter = new FileFilter() { @Override//from w ww . j a v a 2s .c om public boolean accept(File pathname) { return pathname.isFile(); } }; // returns pathnames for files and directory File[] paths = f.listFiles(filter); for (File path : paths) { System.out.println(path); } }
From source file:Main.java
public static void main(String[] args) { String dirPath = "C:\\"; File dir = new File(dirPath); // Create a file filter to exclude any .SYS file FileFilter filter = file -> { if (file.isFile()) { String fileName = file.getName().toLowerCase(); if (fileName.endsWith(".sys")) { return false; }/* w w w . j a v a 2 s .c om*/ } return true; }; File[] list = dir.listFiles(filter); for (File f : list) { if (f.isFile()) { System.out.println(f.getPath() + " (File)"); } else if (f.isDirectory()) { System.out.println(f.getPath() + " (Directory)"); } } }
From source file:Main.java
public static void main(String[] args) { File file = new File("C://FileIO"); boolean isFile = file.isFile(); if (isFile) { System.out.println("a file."); } else {/*w ww. ja va 2 s. c om*/ System.out.println("not a file."); } boolean isDirectory = file.isDirectory(); if (isDirectory) { System.out.println("a directory."); } else { System.out.println("not a directory."); } }
From source file:MainClass.java
public static void main(String[] a) { File myFile = new File("C:" + File.separator + "jdk1.5.0" + File.separator, "File.java"); System.out.println(myFile.isFile()); }
From source file:sample.fa.ScriptRunnerApplicationMac.java
public static void main(String[] args) { SwingUtilities.invokeLater(() -> { ScriptRunnerApplication app = new ScriptRunnerApplication(); app.createGUI();/*from w w w .jav a 2 s . com*/ if (args.length > 0) { File f = new File(args[0]); if (f.isFile()) { app.loadScript(f); } } Application.getApplication().setOpenFileHandler((AppEvent.OpenFilesEvent ofe) -> { List<File> files = ofe.getFiles(); if (files != null && files.size() > 0) { app.loadScript(files.get(0)); } }); }); }
From source file:MainClass.java
public static void main(String[] Args) { String filepath = "C:/myFile.txt"; File aFile = new File(filepath); FileOutputStream outputFile = null; if (aFile.isFile()) { File newFile = aFile;/* www . ja v a 2s .c o m*/ do { String name = newFile.getName(); int period = name.indexOf('.'); newFile = new File(newFile.getParent(), name.substring(0, period) + "_old" + name.substring(period)); } while (newFile.exists()); aFile.renameTo(newFile); } try { outputFile = new FileOutputStream(aFile); System.out.println("myFile.txt output stream created"); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } }
From source file:edu.illinois.cs.cogcomp.nlp.tokenizer.HashCollisionReport.java
/** * Read each test file in the directory, tokenize and create the token view. Then check for * collisions.// w w w . j a v a2 s.c o m * @param args * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length == 0) error("Must pass in the name of a directory with files to test against."); File dir = new File(args[0]); if (!dir.exists()) { error("The directory did not exist : " + dir); } if (!dir.isDirectory()) { error("The path was not a directory : " + dir); } File[] files = dir.listFiles(); for (File file : files) { if (file.isFile()) { String normal = FileUtils.readFileToString(file); TextAnnotationBuilder tabldr = new TokenizerTextAnnotationBuilder(new StatefulTokenizer()); TextAnnotation taNormal = tabldr.createTextAnnotation("test", "normal", normal); List<Constituent> normalToks = taNormal.getView(ViewNames.TOKENS).getConstituents(); HashMap<Integer, Constituent> hashmap = new HashMap<>(); // add each constituent to the map keyed by it's hashcode. Check first to see if the hashcode // is already used, if it is report it. for (Constituent c : normalToks) { int code = c.hashCode(); if (hashmap.containsKey(code)) { Constituent dup = hashmap.get(code); System.err.println(c + " == " + dup); } else { hashmap.put(code, c); } } } } }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:"); // true if the file path is a file, else false boolean bool = f.isFile(); // get the path String path = f.getPath();/*from ww w . jav a2s .co m*/ System.out.println(path + " is file? " + bool); // create new file f = new File("c:/test.txt"); // true if the file path is a file, else false bool = f.isFile(); // get the path path = f.getPath(); System.out.print(path + " is file? " + bool); }
From source file:Empty.java
public static void main(String[] argv) { if (argv.length != 1) { // no progname in argv[0] System.err.println("usage: Empty dirname"); System.exit(1);//from w ww . j av a 2 s .co m } File dir = new File(argv[0]); if (!dir.exists()) { System.out.println(argv[0] + " does not exist"); return; } String[] info = dir.list(); for (int i = 0; i < info.length; i++) { File n = new File(argv[0] + dir.separator + info[i]); if (!n.isFile()) // skip ., .., other directories too continue; System.out.println("removing " + n.getPath()); if (!n.delete()) System.err.println("Couldn't remove " + n.getPath()); } }