List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] argv) throws Exception { Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open();/*w ww. ja v a 2s . c om*/ // From file InputStream is = new BufferedInputStream(new FileInputStream(new File("midifile"))); // From URL // is = new BufferedInputStream(new URL("http://hostname/rmffile") // .openStream()); sequencer.setSequence(is); // Start playing sequencer.start(); }
From source file:MainClass.java
public static void main(String[] args) { long[] primes = new long[] { 1, 2, 3, 5, 7 }; File aFile = new File("C:/test/primes.txt"); FileOutputStream outputFile = null; try {/*from ww w . ja v a 2s .c o m*/ outputFile = new FileOutputStream(aFile); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } FileChannel file = outputFile.getChannel(); final int BUFFERSIZE = 100; ByteBuffer buf = ByteBuffer.allocate(BUFFERSIZE); DoubleBuffer doubleBuf = buf.asDoubleBuffer(); buf.position(8); CharBuffer charBuf = buf.asCharBuffer(); for (long prime : primes) { String primeStr = "prime = " + prime; doubleBuf.put(0, (double) primeStr.length()); charBuf.put(primeStr); buf.position(2 * charBuf.position() + 8); LongBuffer longBuf = buf.asLongBuffer(); longBuf.put(prime); buf.position(buf.position() + 8); buf.flip(); try { file.write(buf); } catch (IOException e) { e.printStackTrace(System.err); } buf.clear(); doubleBuf.clear(); charBuf.clear(); } try { System.out.println("File written is " + file.size() + "bytes."); outputFile.close(); } catch (IOException e) { e.printStackTrace(System.err); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open();/*from w ww . j a v a 2 s .c o m*/ // From file InputStream input = new BufferedInputStream(new FileInputStream(new File("midiaudiofile"))); // From URL input = new BufferedInputStream(new URL("http://hostname/rmffile").openStream()); sequencer.setSequence(input); // Start playing sequencer.start(); }
From source file:SAXSample.java
public static void main(String[] args) throws Exception { File file = new File("book.xml"); SAXParserFactory factory = SAXParserFactory.newInstance(); MyHandler handler = new MyHandler(); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(file, handler);/*from w w w . j av a2 s . c o m*/ SAXBooks books = handler.getBooks(); for (int i = 0; i < books.getBookSize(); i++) { SAXBook book = books.getBook(i); System.out.println(book); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//from www . j av a 2s . 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)); Element newElement = doc.createElement("b"); newElement.appendChild(text2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from www .ja v a 2 s . c o m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getElementById("key1"); NamedNodeMap attrs = element.getAttributes(); String[] names = new String[attrs.getLength()]; for (int i = 0; i < names.length; i++) { names[i] = attrs.item(i).getNodeName(); } for (int i = 0; i < names.length; i++) { attrs.removeNamedItem(names[i]); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//from w ww.jav a2 s.c om factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element root = null; NodeList list = doc.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { if (list.item(i) instanceof Element) { root = (Element) list.item(i); break; } } root = doc.getDocumentElement(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//w w w . j a v a2s . 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)); Element newElement = doc.createElement("b"); newElement.appendChild(text2); element.insertBefore(newElement, text2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w ww .ja v a 2 s. c o m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); NamedNodeMap notations = doc.getDoctype().getNotations(); for (int i = 0; i < notations.getLength(); i++) { Notation notation = (Notation) notations.item(i); String notationName = notation.getNodeName(); String notationPublicId = notation.getPublicId(); String notationSystemId = notation.getSystemId(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml"))); int eventTypeID = reader.nextTag(); reader.require(XMLStreamConstants.START_ELEMENT, null, "person"); eventTypeID = reader.nextTag();//from w w w .j av a 2s . c o m try { reader.require(XMLStreamConstants.START_ELEMENT, null, "first_name"); } catch (XMLStreamException e) { System.out.println("Assertion failed. " + e.getMessage() + " at " + reader.getLocation().getLineNumber() + ":" + reader.getLocation().getColumnNumber()); } System.out.println(reader.getElementText()); }