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 {
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    parser.parse(new File("test.xml"), new DefaultHandler() {

        @Override/*w  w  w . j av  a 2s. c o  m*/
        public void startElement(String uri, String localName, String qName, Attributes atts)
                throws SAXException {
            if (qName.equals("passenger")) {
                System.out.println("id = " + atts.getValue(0));
            }
        }

        @Override
        public void endElement(String uri, String localName, String qName) throws SAXException {
        }

        @Override
        public void characters(char[] ch, int start, int length) throws SAXException {
            String text = new String(ch, start, length);
            if (!text.trim().isEmpty()) {
                System.out.println("name " + text);
            }
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File sourceimage = new File("source.gif");
    Image image = ImageIO.read(sourceimage);

    JFrame frame = new JFrame();
    JLabel label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label, BorderLayout.CENTER);
    frame.pack();//from w  w  w  .  j av a  2  s. co m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(new File("input.xml"));
    NodeList nodeList = document.getElementsByTagName("Item");
    for (int x = 0, size = nodeList.getLength(); x < size; x++) {
        System.out.println(nodeList.item(x).getAttributes().getNamedItem("name").getNodeValue());
    }//from   w w w . j a  va2  s. c o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(new File("yourFile.xml"));
    NodeList nodeList = document.getElementsByTagName("message");
    for (int x = 0, size = nodeList.getLength(); x < size; x++) {
        System.out.println(nodeList.item(x).getAttributes().getNamedItem("to").getNodeValue());
    }/*from   w ww .  j  a  v a  2s . c o m*/
}

From source file:Main.java

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

    System.out.println("City: " + doc.getDocumentElement().getChildNodes().item(0).getFirstChild()
            .getChildNodes().item(0).getAttributes().getNamedItem("data").getNodeValue());

    System.out.println("Postal Code: " + doc.getDocumentElement().getChildNodes().item(0).getFirstChild()
            .getChildNodes().item(1).getAttributes().getNamedItem("data").getNodeValue());

    System.out.println("Date: " + doc.getDocumentElement().getChildNodes().item(0).getFirstChild()
            .getChildNodes().item(4).getAttributes().getNamedItem("data").getNodeValue());
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");

    Icon icon = fileChooser.getIcon(new File("."));
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();//from w ww.  j av a  2 s . co m
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(new File("customer.xsd"));

    JAXBContext jc = JAXBContext.newInstance(Customer.class);

    Customer customer = new Customer();
    // populate the customer object
    JAXBSource source = new JAXBSource(jc, customer);
    schema.newValidator().validate(source);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");

    String name = fileChooser.getName(new File("."));
    frame.add(fileChooser, BorderLayout.CENTER);

    frame.pack();//w ww  .j a va 2 s. c  o m
    frame.setVisible(true);
}

From source file:SaveIt.java

public static void main(String args[]) throws IOException {
    // Read//from   ww w. j  a  v a  2  s  .  c  o  m
    File inputFile = new File("java2s.jpg");
    BufferedImage input = ImageIO.read(inputFile);
    // Convert
    Kernel kernel = new Kernel(3, 3, SHARP);
    ConvolveOp convolveOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    int width = input.getWidth();
    int height = input.getHeight();
    BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    convolveOp.filter(input, output);
    // Save
    File outputFile = new File("java2s.png");
    ImageIO.write(output, "PNG", outputFile);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File dir = new File("Input Directory Root Path Here");
    listFilesInDirectory(dir);//from   w w w .  j a  v a  2 s.co m
}