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:Test.java

public static void main(String[] a) {
    try {/*from  w ww .j a v  a2  s.com*/
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.open(new File("c:\\a.txt"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Test.java

public static void main(String[] a) {
    try {/*  ww w  .j  a  va2s .co m*/
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.print(new File("c:\\a.txt"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File CFile = new File("data.xml");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setIgnoringComments(true);/*w w w  .j  a v  a  2  s .  c o m*/
    factory.setIgnoringElementContentWhitespace(true);
    factory.setValidating(false);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(CFile);

    NodeList pizzas = document.getElementsByTagName("Pizza");

    for (int i = 0; i < pizzas.getLength(); i++) {
        Element pizzaSize = (Element) pizzas.item(i);
        String pSize = pizzaSize.getAttribute("Size");

        if (pSize.equalsIgnoreCase("Large"))
            System.out.println(10.0);
        if (pSize.equalsIgnoreCase("Medium"))
            System.out.println(7.0);
        if (pSize.equalsIgnoreCase("Small"))
            System.out.println(5.0);
    }
}

From source file:AllCapsDemo.java

License:asdf

public static void main(String[] arguments) {
    String sourceName = "asdf";
    try {//from  ww w . jav  a2 s .c o  m
        File source = new File(sourceName);
        File temp = new File("cap" + sourceName + ".tmp");

        FileReader fr = new FileReader(source);
        BufferedReader in = new BufferedReader(fr);

        FileWriter fw = new FileWriter(temp);
        BufferedWriter out = new BufferedWriter(fw);

        boolean eof = false;
        int inChar = 0;
        do {
            inChar = in.read();
            if (inChar != -1) {
                char outChar = Character.toUpperCase((char) inChar);
                out.write(outChar);
            } else
                eof = true;
        } while (!eof);
        in.close();
        out.close();

        boolean deleted = source.delete();
        if (deleted)
            temp.renameTo(source);
    } catch (Exception se) {
        System.out.println("Error - " + se.toString());
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    StreamSource xmlFile = new StreamSource(new File(args[0]));
    StreamSource xsltFile = new StreamSource(new File(args[1]));
    TransformerFactory xsltFactory = TransformerFactory.newInstance();
    Transformer transformer = xsltFactory.newTransformer(xsltFile);

    StreamResult resultStream = new StreamResult(System.out);
    transformer.transform(xmlFile, resultStream);
}

From source file:FileDemo.java

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

    // Display constants
    System.out.println("pathSeparatorChar = " + File.pathSeparatorChar);
    System.out.println("separatorChar = " + File.separatorChar);

    // Test some methods
    File file = new File(args[0]);
    System.out.println("getName() = " + file.getName());
    System.out.println("getParent() = " + file.getParent());
    System.out.println("getAbsolutePath() = " + file.getAbsolutePath());
    System.out.println("getCanonicalPath() = " + file.getCanonicalPath());
    System.out.println("getPath() = " + file.getPath());
    System.out.println("canRead() = " + file.canRead());
    System.out.println("canWrite() = " + file.canWrite());
}

From source file:Main.java

public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {

    Formatter formatter = new Formatter(new File("generated/format.txt"), "ASCII", Locale.getDefault());

    // format a new string
    String name = "from java2s.com";
    formatter.format("Hello %s !", name);

    // print the formatted string
    System.out.println(formatter);

    // flush the formatter. Here it does nothing.
    formatter.flush();// w  ww . ja va 2 s. c  om
    System.out.println("Formatter Flushed.");
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String url = "data.html";
    Document doc = Jsoup.parse(new File(url), "UTF-8");
    Elements rows = doc.select("tr");
    for (Element row : rows) {
        print("---------");
        Elements data = row.getElementsByTag("td");
        print("First Name:%s", data.get(0).text());
        print("Last Name:%s", data.get(1).text());
        print("Date:%s", data.get(2).text());
        print("City:%s", data.get(3).text());
    }// ww  w. j  ava 2 s.  c  o m
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(new File("tds.xml"));
    Attribute attr = (Attribute) XPath.selectSingleNode(doc, "/schedule/@name");
    System.out.println(attr.getValue());

    Element el = new Element("parent").addContent(new Element("child").setAttribute("name", "value"));
    System.out.println(XPath.selectSingleNode(new Attribute("foo", "bar"), "position()"));

    XPath path = XPath.newInstance("/schedule/@name");
    System.out.println(path.valueOf(doc));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage originalImage = ImageIO.read(new File("test.png"));
    int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();

    BufferedImage resizeImageBmp = resizeImage(originalImage, type);
    ImageIO.write(resizeImageBmp, "png", new File("a.png"));

    resizeImageBmp = resizeImageWithHint(originalImage, type);
    ImageIO.write(resizeImageBmp, "png", new File("b.png"));

}