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 image = null;/*from  w  w w.  jav  a  2s.  c  om*/

    URL url = new URL("URL_IMAGE");
    image = ImageIO.read(url);

    ImageIO.write(image, "jpg", new File("C:\\out.jpg"));
    ImageIO.write(image, "gif", new File("C:\\out.gif"));
    ImageIO.write(image, "png", new File("C:\\out.png"));

    System.out.println("Done");
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    BufferedImage large = ImageIO.read(new File("images/a.jpg"));
    BufferedImage small = ImageIO.read(new File("images/b.jpg"));

    int w = large.getWidth();
    int h = large.getHeight();
    int type = BufferedImage.TYPE_INT_RGB;

    BufferedImage image = new BufferedImage(w, h, type);
    Graphics2D g2 = image.createGraphics();
    g2.drawImage(large, 0, 0, null);/* w  w w.ja v a2 s .c o  m*/
    g2.drawImage(small, 10, 10, null);
    g2.dispose();
    ImageIO.write(image, "jpg", new File("new.jpg"));

    JOptionPane.showMessageDialog(null, new ImageIcon(image), "", JOptionPane.PLAIN_MESSAGE);
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    DataOutputStream dos = new DataOutputStream(
            new BufferedOutputStream(new FileOutputStream(new File("temp.tmp"))));
    for (int i = 0; i < 10; i++)
        dos.writeInt(i);/* w  w  w. j  av a2  s.c  om*/
    dos.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ObjectInputStream ois = new ObjectInputStream(
            new GZIPInputStream(new FileInputStream(new File("user.dat"))));

    User admin = (User) ois.readObject();
    User foo = (User) ois.readObject();//w ww .j a v  a2  s. c o m

    ois.close();
    System.out.println("Admin = [" + admin + "]");
    System.out.println("Foo = [" + foo + "]");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setCoalescing(true);/*www .  j  av a  2s. c  om*/

    Document doc = factory.newDocumentBuilder().parse(new File("infilename.xml"));

    // doc will not contain any CDATA nodes
}

From source file:Main.java

public static void main(String[] args) {
    try {// w  ww  .jav a2s. co  m
        String[] cmdArray = new String[2];
        // the program to open
        cmdArray[0] = "notepad.exe";

        // txt file to open with notepad
        cmdArray[1] = "test.txt";

        File dir = new File("c:/");

        String[] envArray = new String[2];
        envArray[0] = "";
        envArray[1] = "";

        Runtime runTime = Runtime.getRuntime();

        Process process = runTime.exec(cmdArray, envArray, dir);

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String argv[]) throws Exception {
    File myfile = new File("data.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(myfile);
    doc.getDocumentElement().normalize();

    System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
    NodeList nList = doc.getElementsByTagName("test");
    for (int temp = 0; temp < nList.getLength(); temp++) {
        Node nNode = nList.item(temp);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element eElement = (Element) nNode;
            System.out.println("First Name : " + getTagValue("id", eElement));
            System.out.println("Last Name : " + getTagValue("result", eElement));
        }//  ww  w.ja v  a  2 s  .c  om
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setIgnoringComments(true);//w  ww  . j a va2 s.c o  m

    Document doc = factory.newDocumentBuilder().parse(new File("infilename.xml"));
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    File stocks = new File("Stocks.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(stocks);
    doc.getDocumentElement().normalize();

    System.out.println(doc.getDocumentElement().getNodeName());
    NodeList nodes = doc.getElementsByTagName("stock");

    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            System.out.println("Stock Symbol: " + getValue("symbol", element));
            System.out.println("Stock Price: " + getValue("price", element));
            System.out.println("Stock Quantity: " + getValue("quantity", element));
        }/*  ww w.j a  v  a 2  s .c  o  m*/
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setIgnoringComments(true);/* w ww  . ja  v  a 2s .co  m*/

    Document doc = factory.newDocumentBuilder().parse(new File("infilename.xml"));
    // doc will not contain any Comment nodes
}