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) {
    long size = FileUtils.sizeOfDirectory(new File("C:/Windows"));
    System.out.println("Size: " + size + " bytes");
}

From source file:Main.java

public static void main(String[] args) {

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

    FilenameFilter filter = new MainFilenameFilter("txt");

    // array of files and directory
    String[] paths = f.list(filter);

    // for each name in the path array
    for (String path : paths) {
        System.out.println(path);
    }//  www.j  ava2s  . co  m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File f = new File("filename");
    RandomAccessFile raf = new RandomAccessFile(f, "rw");

    // Read a character
    char ch = raf.readChar();

    // Seek to end of file
    raf.seek(f.length());/*from  w  w w  .  j  a v a  2 s . com*/

    // Append to the end
    raf.writeChars("aString");
    raf.close();
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:\\temp\\debug.txt");
    try {//from   w  w  w  . j  ava 2s . com
        PrintStream ps = new PrintStream(file);
        System.setOut(ps);
    } catch (IOException e) {
    }
    System.out.println("To File");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Scanner scanner = new Scanner(new File("c:/text.txt"));
    System.out.println(scanner.nextLine());

    scanner.close();/*from  w  w w. j a  v  a  2s  . c o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    String directories = "D:\\a\\b\\c\\d\\e\\f\\g\\h\\i";
    File file = new File(directories);

    boolean result = file.mkdirs();
    System.out.println("Status = " + result);
}

From source file:Main.java

public static void main(String[] argv) {
    // Rename old-dummy.txt to new_dummy.txt
    File oldFile = new File("old_dummy.txt");
    File newFile = new File("new_dummy.txt");

    boolean fileRenamed = oldFile.renameTo(newFile);
    if (fileRenamed) {
        System.out.println(oldFile + "  renamed  to " + newFile);
    } else {//from w  w  w .j  av a  2s.  c  om
        System.out.println("Renaming " + oldFile + "  to " + newFile + "  failed.");
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zipFile = new ZipFile(new File("testfile.zip"), ZipFile.OPEN_READ);

    System.out.println(zipFile.size());
}

From source file:Main.java

public static void main(String[] args) {
    File directory = new File("c:\\");

    if (!directory.isDirectory()) {
        System.out.println("No directory provided");
        return;/*w  ww.  j a v a2 s  .  c  om*/
    }

    FilenameFilter filefilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }
    };

    String[] filenames = directory.list(filefilter);

    for (String name : filenames) {
        System.out.println(name);
    }
}

From source file:Main.java

public static void main(String[] argv) {
    getXMLFiles(new File("c:\\a"));
}