File and Directories access using Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

File and Directories access using Java

Share This

Source code
package com.t4b.test; import java.io.File; public class TestMain { public static void main(String[] args) { File f = new File("Demo.txt"); System.out.println(f.exists()); System.out.println(f.getParent()); System.out.println(f.getPath()); System.out.println(f.getAbsolutePath()); System.out.println(f.canRead()); System.out.println(f.canWrite()); System.out.println(f.canExecute()); System.out.println(f.lastModified()); System.out.println(f.length()); System.out.println(f.isHidden()); } }


package com.t4b.test; import java.io.File; public class TestMain { public static void main(String[] args) { File f = new File("Demo"); if (f.exists() && f.isDirectory()) { System.out.println(f.getAbsolutePath()); String[] files = f.list(); for (String name : files) { File sf = new File(name); System.out.println(sf.getName()); System.out.println(sf.isDirectory()); } } } }

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.