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"); boolean bool = f.setWritable(true, false); System.out.println(bool);//from w w w .ja v a 2s . co m bool = f.canWrite(); System.out.print(bool); }
From source file:Main.java
public static void main(String[] args) { File parent = new File("c:/aFolder"); File aFile = new File(parent, "aFile.txt"); System.out.println(aFile);//c:\aFolder\aFile.txt }
From source file:Main.java
public static void main(String[] args) { File oldName = new File("C:/s.txt"); File newName = new File("C:/d.txt"); if (oldName.renameTo(newName)) System.out.println("File has been renamed"); else//from w w w.j ava 2 s . c om System.out.println("Error renaming the file"); }
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 va 2 s. com*/ } }
From source file:Main.java
public static void main(String[] argv) { getFileExtensionName(new File("a.txt")); }
From source file:Main.java
public static void main(String[] args) { File file1 = new File("C:/File/demo1.txt"); File file2 = new File("C:/FileIO/demo1.txt"); if (file1.compareTo(file2) == 0) { System.out.println("Both paths are same!"); } else {//from w w w .java2s.c o m System.out.println("Paths are not same!"); } }
From source file:Main.java
public static void main(String[] args) { File oldName = new File("C:/s.txt"); File newName = new File("C:/d.txt"); if (oldName.renameTo(newName)) { System.out.println("renamed"); } else {/* w ww .j a va2 s . co m*/ System.out.println("Error"); } }
From source file:FileDemo.java
public static void main(String args[]) { File f1 = new File("/java/COPYRIGHT"); System.out.println("File Name: " + f1.getName()); System.out.println("Path: " + f1.getPath()); System.out.println("Abs Path: " + f1.getAbsolutePath()); System.out.println("Parent: " + f1.getParent()); System.out.println(f1.exists() ? "exists" : "does not exist"); System.out.println(f1.canWrite() ? "is writeable" : "is not writeable"); System.out.println(f1.canRead() ? "is readable" : "is not readable"); System.out.println("is " + (f1.isDirectory() ? "" : "not" + " a directory")); System.out.println(f1.isFile() ? "is normal file" : "might be a named pipe"); System.out.println(f1.isAbsolute() ? "is absolute" : "is not absolute"); System.out.println("File last modified: " + f1.lastModified()); System.out.println("File size: " + f1.length() + " Bytes"); }
From source file:Main.java
public static void main(String[] args) { File f = new File("C:/test.txt"); // set file as read only boolean bool = f.setReadOnly(); System.out.println("setReadonly() succeeded?: " + bool); // checks whether the file is writable bool = f.canWrite();// w w w . ja v a2 s . c o m System.out.print("Is file writable?: " + bool); }
From source file:Main.java
public static void main(String[] args) { File f = new File("C:/test.txt"); // set read permission boolean bool = f.setReadable(true); System.out.println("setReadable() succeeded?: " + bool); // checks whether the file is readable bool = f.canRead();//from www . ja v a 2s. c o m System.out.print("Is file readable?: " + bool); }