Problem URL: http://www.spoj.com/problems/PT07H/
By the way, I tried to read an input by 3 different methods but no success, control never come out of while() loop (i.e., It never detects EOF or EOS).
Here's my code that reads an input XML:
public static void main(String[] args) throws Exception { // Input & Output BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); OutputStream out = new BufferedOutputStream(System.out); int data; char c; String line; StringBuilder xml = new StringBuilder(); // Read input /* // Method-1 Scanner in = new Scanner(System.in); while (in.hasNextLine()) { line = in.nextLine(); for (int i = 0; i < line.length(); i++) { c = line.charAt(i); if (isValid(c)) { xml.append(c); } } } // Method-2 while ((data = br.read()) != -1) { c = (char) data; if (isValid(c)) { xml.append(c); } } */ // Method-3 while ((line = br.readLine()) != null) { for (int i = 0; i < line.length(); i++) { c = line.charAt(i); if (isValid(c)) { xml.append(c); } } } }