List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test.txt"); // returns true if the file can be read boolean bool = f.canRead(); System.out.print("File can be read: " + bool); }
From source file:Main.java
public static void main(String[] args) { File file = new File("C:/demo.txt"); long fileSize = file.length(); System.out.println(fileSize + " bytes"); System.out.println((double) fileSize / 1024 + " KB"); System.out.println((double) fileSize / (1024 * 1024) + "MB"); }
From source file:Main.java
public static void main(String[] args) { File f = new File("test.txt"); // set writable to false f.setWritable(false);//from ww w . j a v a 2s . c om // returns boolean boolean bool = f.canWrite(); System.out.println("Can write to test.txt: " + bool); }
From source file:Main.java
public static void main(String[] args) { File dir = new File("C:/FileIO/DemoDirectory"); boolean isDirectoryCreated = dir.mkdir(); if (isDirectoryCreated) { System.out.println("successfully"); } else {//from w w w .j a va 2 s . c o m System.out.println("not"); } }
From source file:Main.java
public static void main(String[] args) { File dir = new File("C:/1/Parent1/Parent2/DemoDir"); boolean isDirCreated = dir.mkdirs(); if (isDirCreated) System.out.println("created"); else/*from ww w . j a v a 2 s. c o m*/ System.out.println("Failed"); }
From source file:Main.java
public static void main(String[] args) { File f = new File("C:/test.txt"); boolean bool = f.setWritable(true); System.out.println("setWritable() succeeded?: " + bool); bool = f.canWrite();/* w w w. j a va 2 s . c om*/ System.out.print("Is file writable?: " + bool); }
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 . java 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { File file = new File("C:"); long totalSpace = file.getTotalSpace(); System.out.println("Total space on " + file + " = " + totalSpace + "bytes"); // Check the free space in C: long freeSpace = file.getFreeSpace(); System.out.println("Free space on " + file + " = " + freeSpace + "bytes"); }
From source file:Main.java
public static void main(String[] args) { File f = new File("test.txt"); boolean bool = f.setExecutable(true); System.out.println("setExecutable() succeeded?: " + bool); bool = f.canExecute();//w w w. j a va2 s . com System.out.print("Can execute?: " + bool); }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test.txt"); boolean bool = f.exists(); if (bool) {// w w w. j a v a 2 s . c o m long len = f.length(); String path = f.getPath(); System.out.print(path + " file length: " + len); } }