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) {
    File file = new File("sample.txt");

    String content = FileUtils.readFileToString(file);

    System.out.println("File content: " + content);
}

From source file:Main.java

public static void main(String[] args) {
    String filePath = File.separator + "Java" + File.separator + "IO";
    File file = new File(filePath);
    System.out.println(file.getPath());
}

From source file:MainClass.java

public static void main(String[] args) {
    // Create an object that is a directory
    File myDir = new File("C:/Java_Dev");
    System.out.println(new Date(myDir.lastModified()));
}

From source file:MainClass.java

public static void main(String args[]) {

    try {//w w w.j a  v  a  2  s  .  co m

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

        File newFile = new File(args[1]);

        boolean result = oldFile.renameTo(newFile);

        System.out.println(result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

    URL url = file.toURI().toURL();
    URL[] urls = new URL[] { url };

    ClassLoader cl = new URLClassLoader(urls);

    Class cls = cl.loadClass("com.mycompany.MyClass");
}

From source file:MainClass.java

public static void main(String[] a) {
    File aFile = new File("C:/myFile.txt");
    FileInputStream inputFile = null;
    try {// w ww . j  av  a  2s .c o  m
        inputFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:Main.java

public static void main(String[] argv) {
    JFileChooser fileChooser = new JFileChooser(new File("."));
    fileChooser.addChoosableFileFilter(new MyFilter());

    fileChooser.showOpenDialog(null);/*from  w ww  .  ja va  2  s  .  com*/
    System.out.println(fileChooser.getSelectedFile());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File dir = new File("c:\\temp");
    FileFilter fileFilter = new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }//w w w .  j a v  a2 s .  co  m
    };
    File[] files = dir.listFiles(fileFilter);

}

From source file:DirListOnly.java

public static void main(String args[]) {
    String dirname = "/java";
    File f1 = new File(dirname);
    FilenameFilter only = new OnlyExt("html");
    String s[] = f1.list(only);//from  w w  w .  j  a va  2 s. c  om

    for (int i = 0; i < s.length; i++) {
        System.out.println(s[i]);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File dir = new File("c:\\temp");
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return !name.startsWith(".");
        }/*  w  ww  .ja  v  a2s  .  c o  m*/
    };
    String[] children = dir.list(filter);

}