FileDemo.java Source code

Java tutorial

Introduction

Here is the source code for FileDemo.java

Source

import java.io.File;

class FileDemo {

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

        // Display constants
        System.out.println("pathSeparatorChar = " + File.pathSeparatorChar);
        System.out.println("separatorChar = " + File.separatorChar);

        // Test some methods
        File file = new File(args[0]);
        System.out.println("getName() = " + file.getName());
        System.out.println("getParent() = " + file.getParent());
        System.out.println("getAbsolutePath() = " + file.getAbsolutePath());
        System.out.println("getCanonicalPath() = " + file.getCanonicalPath());
        System.out.println("getPath() = " + file.getPath());
        System.out.println("canRead() = " + file.canRead());
        System.out.println("canWrite() = " + file.canWrite());
    }
}