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 {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*from  w ww  .  j a va  2s. com*/
    factory.setExpandEntityReferences(false);
    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");
    NamedNodeMap attrs = element.getAttributes();
    while (attrs.getLength() > 0) {
        attrs.removeNamedItem(attrs.item(0).getNodeName());
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//w  w  w . jav  a2  s .c  o m

    factory.setExpandEntityReferences(false);

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

    visit(doc, 0);
}

From source file:Main.java

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

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//  www  . j a  va2s .  c  o m

    factory.setExpandEntityReferences(false);

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

    Element element = doc.getDocumentElement();

    Text text1 = (Text) element.getFirstChild();
    String string = text1.getData();
}

From source file:Main.java

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

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*from  w w  w.ja  va2  s  . c  o  m*/

    factory.setExpandEntityReferences(false);

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

    Element element = doc.getDocumentElement();
    Comment comment = doc.createComment("A Document Comment");
    element.getParentNode().insertBefore(comment, element);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*  w  w w .ja va 2  s. co  m*/

    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    NodeList list = doc.getElementsByTagName("entry");
    Element element = (Element) list.item(0);

    Element dup = (Element) element.cloneNode(true);

    element.getParentNode().insertBefore(dup, element.getNextSibling());
}

From source file:DirList3.java

public static void main(final String[] args) {
    File path = new File(".");
    String[] list;/*from  w  w w . j av  a2  s .com*/
    if (args.length == 0)
        list = path.list();
    else
        list = path.list(new FilenameFilter() {
            private Pattern pattern = Pattern.compile(args[0]);

            public boolean accept(File dir, String name) {
                return pattern.matcher(new File(name).getName()).matches();
            }
        });
    Arrays.sort(list, new AlphabeticComparator());
    for (int i = 0; i < list.length; i++)
        System.out.println(list[i]);
}

From source file:DirList.java

public static void main(String[] args) {
    File path = new File(".");
    String[] list;/* w  w  w  .j a v  a  2 s.  c o m*/
    if (args.length == 0)
        list = path.list();
    else
        list = path.list(new DirFilter(args[0]));
    Arrays.sort(list, new AlphabeticComparator());
    for (int i = 0; i < list.length; i++)
        System.out.println(list[i]);
}

From source file:Main.java

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

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);/*from   w ww.ja  va  2s  .  co  m*/

    factory.setExpandEntityReferences(false);

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

    Element element = doc.getDocumentElement();
    Text text = doc.createTextNode("data\n");
    element.appendChild(text);

    text = doc.createTextNode("<>&\"'");
    element.appendChild(text);
}

From source file:Main.java

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

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//ww  w  .  j a  v  a  2 s .c o  m

    factory.setExpandEntityReferences(false);

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

    Element element = doc.getDocumentElement();

    Text text1 = (Text) element.getFirstChild();
    String string = text1.getData();

    String word = "some";
    Text text2 = text1.splitText(string.indexOf(word));
}

From source file:Main.java

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

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//from   w  ww  . j a  va  2s.com

    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = (Element) doc.getElementsByTagName("b").item(0);

    Node parent = element.getParentNode();

    parent.removeChild(element);

    parent.normalize();

}