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 f = new File("c:/a/b/a/test.txt");

    URL uri;// w  ww  . j a  v a2 s .  c  o  m
    try {
        uri = f.toURL();
        System.out.println("uri: " + uri);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    File games = new File("C:\\Test");
    File[] files = games.listFiles();
    for (File file : files) {
        System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file"));
    }//from w  w w  .j  a  va  2s. c o  m
    String[] xfiles = games.list();
    for (String file : xfiles) {
        System.out.println("File = " + file);
    }
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (name.endsWith(".txt")) {
                return true;
            }
            return false;
        }
    };

    File[] yfiles = games.listFiles(filter);
    for (File doc : yfiles) {
        System.out.println("Doc file = " + doc);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("hello.txt");
    FileReader fr = new FileReader(f);

    char[] c = new char[(int) f.length()];
    char[] cnew = new char[(int) f.length()];
    StringBuffer sbuf = new StringBuffer();
    fr.read(c, 0, (int) f.length());

    int len = (int) f.length();

    for (int i = 0, j = len - 1; i < len; i++, j--) {
        cnew[i] = c[j];/* w w w.  j  a v a  2s .  com*/
        sbuf.append(cnew[i]);
    }

    System.out.println(sbuf.toString());
    fr.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("Main.java");
    FileReader fr = new FileReader(f);

    char[] c = new char[(int) f.length()];
    char[] cnew = new char[(int) f.length()];
    StringBuffer sbuf = new StringBuffer();
    fr.read(c, 0, (int) f.length());

    int len = (int) f.length();

    for (int i = 0, j = len - 1; i < len; i++, j--) {
        cnew[i] = c[j];//from   ww w .  ja v a 2  s  . com
        sbuf.append(cnew[i]);
    }

    System.out.println(sbuf.toString());
    fr.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter(new File("c:/abc.txt"), true);
    fileWriter.append("java2s.com");
    fileWriter.close();/*from www .ja  va2s  . c o  m*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter(new File("c:/abc.txt"));
    fileWriter.append("java2s.com");
    fileWriter.close();/*from ww w  .  j  av a  2 s .  com*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileReader fileReader = new FileReader(new File("c:/abc.txt"));
    System.out.println(fileReader.read());
    fileReader.close();//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 file = new File("filename");

    URI uri = file.toURI();//  w  ww .j a  v a 2  s  .  c  om
    file = new File(uri.toURL().getFile());
    InputStream is = uri.toURL().openStream();
    is.close();
}

From source file:Main.java

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

    URI uri = file.toURI();//from   ww w  .j a v  a  2  s. com
    System.out.println(uri);
    file = new File(uri.toURL().getFile());
    InputStream is = uri.toURL().openStream();
    is.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("c:\\class\\");
    URL url = file.toURI().toURL();
    URL[] urls = new URL[] { url };
    ClassLoader loader = new URLClassLoader(urls);
    Class cls = loader.loadClass("user.informatin.Class");
}