List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.parse(new File("D:/test.xml")); NodeList elt = doc.getElementsByTagName("EMPLOYEE"); for (int k = 0; k < elt.getLength(); k++) { Node firstNode3 = elt.item(k); Element elt1 = (Element) firstNode3; String att = elt1.getAttribute("PERMANENT"); System.out.println("\n\nPERMANENT: " + att); NodeList nodes = elt1.getElementsByTagName("DETAILS"); for (int i = 0; i < nodes.getLength(); i++) { Node childNode = nodes.item(i); Element elt2 = (Element) childNode; System.out.println("---" + elt2.getNodeName()); System.out.println("NAME:" + elt2.getAttribute("NAME")); System.out.println("ID:" + elt2.getAttribute("ID")); System.out.println("AGE:" + elt2.getAttribute("AGE")); }// ww w. j a va2 s . c o m } }
From source file:MainClass.java
public static void main(String[] args) { String[] phrases = { "A", "B 1", "C 1.3" }; String dirname = "C:/test"; String filename = "Phrases.txt"; File dir = new File(dirname); File aFile = new File(dir, filename); FileOutputStream outputFile = null; try {/*from w w w. j a va 2s .com*/ outputFile = new FileOutputStream(aFile, true); } catch (FileNotFoundException e) { e.printStackTrace(System.err); } FileChannel outChannel = outputFile.getChannel(); ByteBuffer buf = ByteBuffer.allocate(1024); System.out.println(buf.position()); System.out.println(buf.limit()); System.out.println(buf.capacity()); CharBuffer charBuf = buf.asCharBuffer(); System.out.println(charBuf.position()); System.out.println(charBuf.limit()); System.out.println(charBuf.capacity()); Formatter formatter = new Formatter(charBuf); int number = 0; for (String phrase : phrases) { formatter.format("%n %s", ++number, phrase); System.out.println(charBuf.position()); System.out.println(charBuf.limit()); System.out.println(charBuf.capacity()); charBuf.flip(); System.out.println(charBuf.position()); System.out.println(charBuf.limit()); System.out.println(charBuf.length()); buf.limit(2 * charBuf.length()); // Set byte buffer limit System.out.println(buf.position()); System.out.println(buf.limit()); System.out.println(buf.remaining()); try { outChannel.write(buf); buf.clear(); charBuf.clear(); } catch (IOException e) { e.printStackTrace(System.err); } } try { outputFile.close(); } catch (IOException e) { e.printStackTrace(System.err); } }