List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("user.txt"); FileWriter writer = new FileWriter(file, true); writer.write("username=java;password=secret" + System.getProperty("line.separator")); writer.flush();/*from www . j ava2s .c o m*/ writer.close(); }
From source file:Main.java
public static void main(String[] args) { String f1 = "run.bat"; long d1 = new File(f1).lastModified(); String f2 = "build.xml"; long d2 = new File(f2).lastModified(); String relation;/*from w w w. ja v a 2 s . co m*/ if (d1 == d2) relation = "the same age as"; else if (d1 < d2) relation = "older than"; else relation = "newer than"; System.out.println(f1 + " is " + relation + ' ' + f2); }
From source file:Main.java
public static void main(String[] args) { String filePath = "C:/Text.txt"; File file = new File(filePath); if (file.canWrite()) { System.out.println("writable"); } else {//w ww. j a v a 2 s.c om System.out.println("not writable"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = null;//w w w. ja v a 2s .c om File dir = new File("C:/"); file = File.createTempFile("JavaTemp", ".javatemp", dir); System.out.println(file.getPath()); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("data.txt"); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); }/*from w ww . j a v a2s . com*/ }
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test"); FileFilter filter = new FileFilter() { @Override/*from ww w . j a v a 2 s . 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:MainClass.java
public static void main(String[] args) { File cwd = new File(System.getProperty("user.dir")); File[] htmlFiles = cwd.listFiles(new HTMLFileFilter()); for (int i = 0; i < htmlFiles.length; i++) { System.out.println(htmlFiles[i]); }//from www. j a v a2 s .c om }
From source file:Main.java
public static void main(String[] args) { File file = new File("c:\\java.exe"); long size = file.length(); String display = FileUtils.byteCountToDisplaySize(size); System.out.println("Name = " + file.getName()); System.out.println("size = " + size); System.out.println("Display = " + display); }
From source file:Main.java
public static void main(String[] args) throws Exception { // create new files File f = new File("test.txt"); String path = f.getCanonicalPath(); System.out.print("Absolute Pathname " + path); }
From source file:Main.java
public static void main(String[] args) throws Exception { // create new files File f = new File("c:/"); long size = f.getFreeSpace(); System.out.print(size);/*w w w . java 2s . c o m*/ }