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) throws Exception {
    File file = new File("ReadOnly.txt");
    file.createNewFile();/*from w  ww  .j av a 2  s  .  c om*/
    file.setReadOnly();

    if (file.canWrite()) {
        System.out.println("writable!");
    } else {
        System.out.println("read only!");
    }
}

From source file:Main.java

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

    boolean success = (new File("directoryName")).mkdirs();
    if (!success) {
        System.out.println("Directory creation failed");
    }/*w ww  .j a  va  2s  .  c  o m*/
}

From source file:Main.java

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

    File file1 = new File("./filename");
    File file2 = new File("filename");
    System.out.println(file1.equals(file2));

    file1 = file1.getCanonicalFile();//from w ww.j ava2  s .c  om
    file2 = file2.getCanonicalFile();
    System.out.println(file1.equals(file2));
}

From source file:Main.java

public static void main(String[] args) {
    File f = new File("C:/test.txt");
    long millisec = new Date().getTime();

    // set last modified time
    boolean bool = f.setLastModified(millisec);

    System.out.println("lastModified() succeeded?: " + bool);

}

From source file:Main.java

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

    String[] children = dir.list();
    if (children == null) {
        System.out.println("does not exist or is not a directory");
    } else {//from www  .  java 2  s.c o  m
        for (int i = 0; i < children.length; i++) {
            String filename = children[i];
            System.out.println(filename);
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    try {//from  ww  w .j  a v a  2s  . c o  m
        File testFile = new File("C:\\books\\2004\\test.txt");
        System.out.println(testFile.toURI().toString());
    } catch (Exception exception) {
        System.out.println("exception");
    }
}

From source file:Touch.java

public static void main(String[] args) {
    String[] names = new File(".").list();

    Date current = new Date();

    for (int i = 0; i < names.length; i++) {
        File f = new File(names[i]);
        f.setLastModified(current.getTime());
    }/*  www .  j a  va 2 s. c  o  m*/
}

From source file:Main.java

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

From source file:Attr.java

public static void main(String args[]) {
    File path = new File(args[0]); // grab command-line argument
    String exists = getYesNo(path.exists());
    String canRead = getYesNo(path.canRead());
    String canWrite = getYesNo(path.canWrite());
    String isFile = getYesNo(path.isFile());
    String isHid = getYesNo(path.isHidden());
    String isDir = getYesNo(path.isDirectory());
    String isAbs = getYesNo(path.isAbsolute());
    System.out.println("File attributes for '" + args[0] + "'");
    System.out.println("Exists    : " + exists);
    if (path.exists()) {
        System.out.println("Readable   : " + canRead);
        System.out.println("Writable   : " + canWrite);
        System.out.println("Is directory : " + isDir);
        System.out.println("Is file    : " + isFile);
        System.out.println("Is hidden   : " + isHid);
        System.out.println("Absolute path : " + isAbs);
    }/*from w  w w .  j  a  v a 2  s .  c  o  m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file1 = new File("a");
    File file2 = new File("a");
    File file3 = new File("b");

    int ihc1 = System.identityHashCode(file1);
    System.out.println(ihc1);/*w  ww .  j a va  2s.  c o  m*/
    int ihc2 = System.identityHashCode(file2);
    System.out.println(ihc2);
    int ihc3 = System.identityHashCode(file3);
    System.out.println(ihc3);

}