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) throws Exception {
    BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
    ImageIO.write(bi, "png", new File("test.png"));
}

From source file:Main.java

public static void main(String[] arg) throws Throwable {
    File f = new File(arg[0]);
    InputStream in = new FileInputStream(f);

    byte[] buff = new byte[8000];

    int bytesRead = 0;

    ByteArrayOutputStream bao = new ByteArrayOutputStream();

    while ((bytesRead = in.read(buff)) != -1) {
        bao.write(buff, 0, bytesRead);// w ww  .ja  va 2 s.c  om
    }
    in.close();

    byte[] data = bao.toByteArray();

    ByteArrayInputStream bin = new ByteArrayInputStream(data);
    System.out.println(bin.available());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage bsrc = ImageIO.read(new File("a.jpg"));
    BufferedImage bdest = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bdest.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance(2, 2);
    g.drawRenderedImage(bsrc, at);//from w  w w. j a va  2 s  .c o m
    ImageIO.write(bdest, "JPG", new File("b.jpg"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    AudioFileFormat fformat = AudioSystem.getAudioFileFormat(new File("audiofile"));

    fformat = AudioSystem.getAudioFileFormat(new URL("http://hostname/audiofile"));

    if (fformat.getType() == AudioFileFormat.Type.AIFC) {
    } else if (fformat.getType() == AudioFileFormat.Type.AIFF) {
    } else if (fformat.getType() == AudioFileFormat.Type.AU) {
    } else if (fformat.getType() == AudioFileFormat.Type.WAVE) {
    }/*from  w ww . j  av  a  2 s.  c o m*/
}

From source file:Main.java

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

    boolean append = false;

    FileChannel wChannel = new FileOutputStream(file, append).getChannel();

    wChannel.write(bbuf);/*from w w w  .java  2s.c om*/

    wChannel.close();
}

From source file:DirList.java

public static void main(String[] args) {
    System.out.print("\nEnter a path: ");
    String path = sc.nextLine();//from   w w w .ja  v a 2s  . c  o m
    File dir = new File(path);
    if (!dir.exists() || !dir.isDirectory())
        System.out.println("\nThat directory doesn't exist.");
    else {
        System.out.println("\nListing directory tree of:");
        System.out.println(dir.getPath());
        listDirectories(dir, "  ");
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    FileChannel fc = new RandomAccessFile(new File("temp.tmp"), "rw").getChannel();
    IntBuffer ib = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size()).asIntBuffer();
    ib.put(0);// w ww. jav  a  2  s .c  o m
    for (int i = 1; i < 10; i++)
        ib.put(ib.get(i - 1));
    fc.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket socket = new Socket("localhost", 8000);
    File file = new File("C:/Users/abc/Desktop/image.jpg");
    FileInputStream fileInputStream = new FileInputStream(file);

    byte[] fileBytes = new byte[(int) file.length()];
    OutputStream outputStream = socket.getOutputStream();
    int content;// ww  w  .j  av  a2s.c  om
    while ((content = fileInputStream.read(fileBytes)) != -1) {
        outputStream.write(fileBytes, 0, (int) file.length());
    }

    System.out.println("file size is " + fileBytes.length);
    for (byte a : fileBytes) {
        System.out.println(a);
    }
    socket.close();
    fileInputStream.close();
}

From source file:Main.java

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

    FileInputStream fin = null;/*from w  w w .  j  a v  a 2s . c  o m*/
    FileOutputStream fout = null;

    File file = new File("C:/myfile1.txt");

    fin = new FileInputStream(file);
    fout = new FileOutputStream("C:/myfile2.txt");

    byte[] buffer = new byte[1024];
    int bytesRead;
    while ((bytesRead = fin.read(buffer)) > 0) {
        fout.write(buffer, 0, bytesRead);
    }
    fin.close();
    fout.close();
}

From source file:MainClass.java

public static void main(String[] args) {
    File myDir = new File("C:/");
    // Define a filter for java source files beginning with F
    FilenameFilter select = new FileListFilter("F", "java");

    File[] contents = myDir.listFiles(select);

    if (contents != null) {
        System.out.println(//from   www .  ja  v  a 2 s  .c o m
                "\nThe " + contents.length + " matching items in the directory, " + myDir.getName() + ", are:");
        for (File file : contents) {
            System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file")
                    + " last modified on\n" + new Date(file.lastModified()));
        }
    } else {
        System.out.println(myDir.getName() + " is not a directory");
    }
    return;
}