List of usage examples for java.io File File
public File(URI uri)
From source file:Test.java
public static void main(String[] args) throws Exception { final URL test = Test.class.getResource("/"); System.out.println(test);/* w w w. j a v a 2s . c om*/ final URL url = Test.class.getResource("/resources/test.txt"); System.out.println(url); if (url == null) { System.out.println("URL is null"); } else { final File file = new File(url.toURI()); final FileReader reader = new FileReader(file); final char[] buff = new char[20]; final int l = reader.read(buff); System.out.println(new String(buff, 0, l)); reader.close(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuild = dbf.newDocumentBuilder(); Document doc = docBuild.parse(new File("test2.xml")); Element x = doc.getDocumentElement(); NodeList m = x.getChildNodes(); for (int i = 0; i < m.getLength(); i++) { Node it = m.item(i);/* www .j ava2s.com*/ if (it.getNodeType() == 3) { System.out.println(it.getNodeValue()); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w w w . j av a2 s. c o m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = (Element) doc.getElementsByTagName("junk").item(0); element.getParentNode().removeChild(element); }
From source file:Play.java
public static void main(String args[]) { try {/*from w w w . j a v a2 s . c o m*/ // Loop URL url = new URL("http://java.sun.com/applets/other/Hangman/audio/whoopy.au"); AudioClip clip = Applet.newAudioClip(url); clip.loop(); Thread.sleep(5000); //Play File file = new File("bark.wav"); clip = Applet.newAudioClip(file.toURL()); clip.play(); Thread.sleep(500); System.exit(0); } catch (InterruptedException e) { } catch (MalformedURLException e) { } }
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("data.xsd")); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);//from w ww . j ava2s. co m dbf.setSchema(schema); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(new File("data.xml")); Element result = document.getElementById("abc"); System.out.println(result); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w w w .java 2 s . co m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); NamedNodeMap attrs = element.getAttributes(); int numAttrs = attrs.getLength(); for (int i = 0; i < numAttrs; i++) { Attr attr = (Attr) attrs.item(i); String attrName = attr.getNodeName(); String attrValue = attr.getNodeValue(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from ww w. ja v a 2 s. c o m*/ factory.setExpandEntityReferences(false); Document doc1 = factory.newDocumentBuilder().parse(new File("filename")); NodeList list = doc1.getElementsByTagName("entry"); Element element = (Element) list.item(0); Document doc2 = factory.newDocumentBuilder().parse(new File("infilename2.xml")); Node dup = doc2.importNode(element, true); doc2.getDocumentElement().appendChild(dup); }
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 2 s. co m*/ // Prevent expansion of entity references factory.setExpandEntityReferences(false); // Create the builder and parse the file Document doc = factory.newDocumentBuilder().parse(new File("filename")); }
From source file:Main.java
public static void main(String[] args) throws IOException { String path = "C:/Pictures/"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); File folder = new File(path); File[] listOfFiles = folder.listFiles(); DefaultListModel listModel = new DefaultListModel(); int count = 0; for (int i = 0; i < listOfFiles.length; i++) { String name = listOfFiles[i].toString(); if (name.endsWith("jpg")) { ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i])); listModel.add(count++, ii);/*w ww .ja v a 2s . c o m*/ } } JList lsm = new JList(listModel); lsm.setVisibleRowCount(1); frame.add(new JScrollPane(lsm)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from www. j a va 2 s . c om*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); removeAll(doc, Node.ELEMENT_NODE, "junk"); removeAll(doc, Node.COMMENT_NODE, null); doc.normalize(); }