Example usage for java.io File File

List of usage examples for java.io File File

Introduction

In this page you can find the example usage for java.io File File.

Prototype

public File(URI uri) 

Source Link

Document

Creates a new File instance by converting the given file: URI into an abstract pathname.

Usage

From source file:Main.java

public static void main(String[] args) {

    File f = new File("c:");

    boolean bool = f.isDirectory();

    String path = f.getPath();/*from  www .  j a  va 2 s  .  c om*/

    System.out.println(path + " is directory? " + bool);

    f = new File("c:/test.txt");

    bool = f.isDirectory();

    path = f.getPath();

    System.out.print(path + " is directory? " + bool);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    boolean success = (new File("directoryName")).mkdir();
    if (!success) {
        System.out.println("Directory creation failed");
    }/*from   w  w  w .  j a  v a 2 s  .  com*/
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("Main.java");
    Long lastModified = file.lastModified();
    Date date = new Date(lastModified);
    System.out.println(date);/*from w  ww  . j a  v a  2  s  . c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    File f = new File("c:/a/b/a/test.txt");

    // returns the uri string
    URI uri = f.toURI();//from   www . j ava2s .c o m

    System.out.println("uri: " + uri);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    visitAllDirs(new File("c:/"));
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    new File("newFile.txt").createNewFile();
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:/ReadText.txt");
    System.out.println(file.lastModified());

    System.out.println(file.setLastModified(new Date().getTime()));
    System.out.println(new Date(file.lastModified()));
}

From source file:MainClass.java

public static void main(String[] args) {

    File absolute = new File("/public/html/javafaq/index.html");
    File relative = new File("html/javafaq/index.html");

    System.out.println("absolute: ");
    System.out.println(absolute.getName());
    System.out.println(absolute.getPath());

    System.out.println("relative: ");
    System.out.println(relative.getName());
    System.out.println(relative.getPath());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("test.txt");

    // create new file in the system
    f.createNewFile();/*from w w  w  .j  ava  2 s.co  m*/

    // create new file object from the absolute path
    File f1 = f.getAbsoluteFile();

    System.out.println(f1);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    boolean success = (new File("directoryName")).delete();
    if (!success) {
        System.out.println("Deletion failed");
    }/*w  w  w  . j a v a2  s.  c  o  m*/
}