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[] argv) throws Exception {
    JFileChooser chooser = new JFileChooser();
    File f = new File(new File("filename.txt").getCanonicalPath());

    chooser.setDragEnabled(true);// w w  w .  jav a2 s  .c om
    chooser.showDialog(new JFrame(""), null);
    File curFile = chooser.getSelectedFile();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("filename");
    FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
    MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_WRITE, 0, (int) channel.size());

    buf.put(0, (byte) 0xFF);

    buf.force();/*from  w ww  .ja  v  a2 s  .c o m*/

    channel.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    long length = new File("test.txt").length();
    MappedByteBuffer in = new FileInputStream("test.txt").getChannel().map(FileChannel.MapMode.READ_ONLY, 0,
            length);//from  w ww .  j av a 2s  .c o m
    int i = 0;
    while (i < length)
        System.out.print((char) in.get(i++));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("filename");
    FileChannel roChannel = new RandomAccessFile(file, "r").getChannel();
    ByteBuffer readonlybuffer = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int) roChannel.size());

    FileChannel rwChannel = new RandomAccessFile(file, "rw").getChannel();
    ByteBuffer writeonlybuffer = rwChannel.map(FileChannel.MapMode.READ_WRITE, 0, (int) rwChannel.size());

    // Create a private (copy-on-write) memory-mapped file.
    FileChannel pvChannel = new RandomAccessFile(file, "rw").getChannel();

    ByteBuffer privatebuffer = roChannel.map(FileChannel.MapMode.READ_WRITE, 0, (int) rwChannel.size());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("c:/mysql-connector-java-5.1.18-bin.jar");
    URLClassLoader urlCl = new URLClassLoader(new URL[] { f.toURL() }, System.class.getClassLoader());

    Class mySqlDriver = urlCl.loadClass("com.mysql.jdbc.Driver");
    System.out.println(mySqlDriver.newInstance());
    System.out.println("Is this interface? = " + mySqlDriver.isInterface());

    Class interfaces[] = mySqlDriver.getInterfaces();
    int i = 1;/*w  w  w.  j  av  a2 s. c  o  m*/
    for (Class _interface : interfaces) {
        System.out.println("Implemented Interface Name " + (i++) + " = " + _interface.getName());
    }

    Constructor constructors[] = mySqlDriver.getConstructors();
    for (Constructor constructor : constructors) {
        System.out.println("Constructor Name = " + constructor.getName());
        System.out.println("Is Constructor Accessible? = " + constructor.isAccessible());
    }
}

From source file:MainClass.java

public static void main(String[] a) {

    FileReader fr;/*from www  . ja  va2 s .c om*/
    try {
        fr = new FileReader(new File("yourFile.txt"));
        BufferedReader br = new BufferedReader(fr);
        String line = br.readLine();
        while (line != null) {
            System.out.println(line);
            line = br.readLine();
        }
        br.close();

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:Main.java

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

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }/*  w  ww . j a v  a  2s  .co m*/
}

From source file:Main.java

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

    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }/*from   w w w  . ja v a2  s . co  m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage img = ImageIO.read(new File("c:/Java_Dev/a.jpg"));
    int height = img.getHeight();
    int width = img.getWidth();

    System.out.println(height + "  " + width + " " + img.getRGB(30, 30));

    for (int h = 1; h < height; h++) {
        for (int w = 1; w < width; w++) {
            int rgb = img.getRGB(w, h);
            int red = (rgb >> 16) & 0x000000FF;
            int green = (rgb >> 8) & 0x000000FF;
            int blue = (rgb) & 0x000000FF;

            if (red == 0 && green == 0 && blue == 0) {
                System.out.println("Black");
            }//from  www  .j a v  a  2  s.  c o  m
        }
    }
}

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.getComment());
    Enumeration zipEntries = zipFile.entries();

    while (zipEntries.hasMoreElements()) {
        System.out.println(((ZipEntry) zipEntries.nextElement()).getName());
    }/*ww  w.ja v  a  2s. c om*/
}