List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("filename"); long modifiedTime = file.lastModified(); // 0L is returned if the file does not exist long newModifiedTime = System.currentTimeMillis(); boolean success = file.setLastModified(newModifiedTime); if (!success) { // operation failed. }/*from ww w. ja va 2 s .c om*/ }
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();//ww w . ja v a2 s . c o 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:Main.java
public static void main(String[] args) { // create new files File f = new File("test.txt"); String path = f.getAbsolutePath(); System.out.print("Absolute Pathname " + path); }
From source file:Main.java
public static void main(String[] args) { // create new file File f = new File("test.txt"); // tries to delete a non-existing file boolean bool = f.delete(); System.out.println("File deleted: " + bool); }
From source file:Main.java
public static void main(String[] args) { // create new file File f = new File("c:/test"); // returns pathnames for files and directory File[] paths = f.listFiles(); // for each pathname in pathname array for (File path : paths) { System.out.println(path); }// w w w. j a v a 2s. c o m }
From source file:Main.java
public static void main(String[] args) { // create new files File f = new File("test.txt"); File f1 = new File("test1.txt"); // returns boolean boolean bool = f.equals(f1); System.out.println("Equal: " + bool); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("Writable.txt"); file.createNewFile();/* ww w . j av a 2 s . c o m*/ file.setReadOnly(); if (file.canWrite()) { System.out.println("File is writable!"); } else { System.out.println("File is in read only mode!"); } file.setWritable(true); if (file.canWrite()) { System.out.println("File is writable!"); } else { System.out.println("File is in read only mode!"); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { File file = new File("D:\\test\\test.java"); String parentPath = file.getParent(); System.out.println(parentPath); File parentDir = file.getParentFile(); System.out.println(parentDir); parentPath = parentDir.getParent();/*from www.j av a2 s. c o m*/ System.out.println(parentPath); parentDir = parentDir.getParentFile(); System.out.println(parentDir); parentPath = parentDir.getParent(); System.out.println(parentPath); parentDir = parentDir.getParentFile(); System.out.println(parentDir); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("c:\\temp\\test.bmp"); Desktop dt = Desktop.getDesktop(); dt.open(f);//from www .ja v a 2 s.co m System.out.println("Done."); }
From source file:Main.java
public static void main(String[] args) { // create new file File f = new File("c:/test.txt"); // true if the file path is a hidden file boolean bool = f.isHidden(); // get the path String path = f.getPath();/*from w w w . j a v a 2s . c o m*/ System.out.print(path + " is file hidden? " + bool); }