Java 1.7 Snippets
Jump to navigation
Jump to search
Using an Iterator to Read a File
try { lines = Files.readAllLines(Paths.get("Request.xml"), StandardCharsets.UTF_8); } catch (Exception e) { System.out.println("Could not read XML file: " + e.toString()); lr.abort(); } if (lines != null) { for (Iterator<String> i = lines.iterator(); i.hasNext(); ) { String item = i.next(); System.out.println(item); } // or for (String line : lines) { System.out.println(line); } }