Difference between revisions of "Java 1.7 Snippets"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (Created page with " =Using an Iterator to Read a File= <pre> try { lines = Files.readAllLines(Paths.get("Request.xml"), StandardCharsets.UTF_8); } catch (Exception e) { System.out.println("Co...") |
(No difference)
|
Latest revision as of 17:47, 14 January 2016
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);
}
}