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:ROW.java

public static void main(String[] args) {
    File filespec = new File("c:\text.txt");

    if (filespec.setWritable(false))
        System.out.println(filespec + " made read-only");
    else//from   ww w. j av a2  s  .  c  om
        System.out.println("Permission denied");
    if (filespec.setWritable(true))
        System.out.println(filespec + " made writable");
    else
        System.out.println("Permission denied");

    System.out.println(filespec + " is currently " + (filespec.canWrite() ? "writable" : "read-only"));
}

From source file:Main.java

public static void main(String[] args) {

    File directory = new File("C:/temp/temp1/temp2/temp3");
    if (directory.mkdir()) {
        System.out.println("Success mkdir");
    } else {/*from w  ww .  j  av a2 s.  c o  m*/
        if (directory.mkdirs()) {
            System.out.println("Success mkdirs");
        } else {
            System.out.println("Failed");
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C://FileIO//demo.txt");
    System.out.println("last modifed:" + new Date(file.lastModified()));
}

From source file:Main.java

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

    // tries to create new file in the system
    boolean bool = f.createNewFile();

    System.out.println("File created: " + bool);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("test.java");
    String parentPath = file.getParent();
    System.out.println(parentPath);
    File parentDir = file.getParentFile();

    System.out.println(parentDir);
}

From source file:DirectoryTree.java

public static void main(String args[]) {
    File file = new File(args[0]);
    if (!file.exists()) {
        System.out.println(args[0] + " does not exist.");
        return;/*from   w ww  .  j a va 2s . c  o m*/
    }
    tree(args[0]);
}

From source file:Main.java

public static void main(String[] args) {

    File f = new File("test.txt");
    File f1 = new File("File/test1.txt");

    // returns integer value
    int value = f.compareTo(f1);

    if (value == 0) {
        System.out.print(" = ");
    } else if (value > 0) {
        System.out.print(" >  ");
    } else {// w w  w . j av  a  2  s.  c  o m
        System.out.print(" < ");
    }
    System.out.print("Value returned: " + value);

}

From source file:Main.java

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

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C://FileIO");
    boolean isFile = file.isFile();
    if (isFile) {
        System.out.println("a file.");
    } else {//from   www  .  jav a2s  . co  m
        System.out.println("not a file.");
    }
    boolean isDirectory = file.isDirectory();

    if (isDirectory) {
        System.out.println("a directory.");
    } else {
        System.out.println("not a directory.");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("filename");
    File dir = new File("directoryname");

    boolean success = file.renameTo(new File(dir, file.getName()));
    if (!success) {
        System.out.println("File was not successfully moved");
    }/*from   w ww . j  a  va  2s  .c  om*/
}