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 {

    // create new files
    File f = new File("test.txt");

    File path = f.getCanonicalFile();

    System.out.print("Absolute Pathname " + path);

}

From source file:Main.java

public static void main(String[] args) {
    String filePath = "C:/Text.txt";
    File file = new File(filePath);

    if (file.canRead()) {
        System.out.println("readable");
    } else {//from   w  ww .ja v  a 2  s . c o m
        System.out.println("not readable");
    }
}

From source file:Main.java

public static void main(String[] args) {

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

    boolean bool = f.exists();

    // if path exists
    if (bool) {//from   www.  java2 s  . co m
        // returns the time file was last modified
        long millisec = f.lastModified();

        // date and time
        Date dt = new Date(millisec);

        // path
        String path = f.getPath();

        System.out.print(path + " last modified at: " + dt);
    }

}

From source file:Main.java

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

    File f = File.createTempFile("tmp", ".txt", new File("C:/"));

    System.out.println("File path: " + f.getAbsolutePath());

}

From source file:PathInfo.java

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

    File f = new File(args[0]);

    System.out.println("Absolute path = " + f.getAbsolutePath());
    System.out.println("Canonical path = " + f.getCanonicalPath());
    System.out.println("Name = " + f.getName());
    System.out.println("Parent = " + f.getParent());
    System.out.println("Path = " + f.getPath());
    System.out.println("Absolute? = " + f.isAbsolute());
}

From source file:FileUtil.java

public static void main(String[] a) throws IOException {
    showDir(1, new File("d:\\Java_Dev"));
}

From source file:Main.java

public static void main(String[] argv) {
    // Create a File object
    File dummyFile = new File("dummy.txt");

    // Check for the file's existence
    boolean fileExists = dummyFile.exists();
    if (fileExists) {
        System.out.println("The dummy.txt  file exists.");
    } else {//  www . j a  v a 2  s .  com

        System.out.println("The dummy.txt  file does  not  exist.");
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("C:/String.txt");
    FileInputStream fin = new FileInputStream(file);

    byte fileContent[] = new byte[(int) file.length()];
    fin.read(fileContent);/*from w  w  w.j  a  va  2s.  c o m*/
    System.out.println(new String(fileContent));
}

From source file:DirList.java

public static void main(String args[]) {
    String dirname = "/java";
    File f1 = new File(dirname);

    if (f1.isDirectory()) {
        System.out.println("Directory of " + dirname);
        String s[] = f1.list();/*from   w  w w  . j av  a2  s .co m*/

        for (int i = 0; i < s.length; i++) {
            File f = new File(dirname + "/" + s[i]);
            if (f.isDirectory()) {
                System.out.println(s[i] + " is a directory");
            } else {
                System.out.println(s[i] + " is a file");
            }
        }
    } else {
        System.out.println(dirname + " is not a directory");
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {//  w ww  . ja  v a 2  s .c o  m
        File file = new File("myfile.txt");
        if (file.createNewFile())
            System.out.println("Success!");
        else
            System.out.println("Error, file already exists.");
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}