CovertToSingleLine.java

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class CovertToSingleLine {

 /**
* @param args
*/
public static void main(String[] args) {
String inputFile = “C:\\filename.xml”;
System.out.println(“Reading input file ” + inputFile + ” … “);
try {
System.out.println(readAllLinesIntoOne(inputFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

 private static String readAllLinesIntoOne(String inputFile)
throws FileNotFoundException, IOException {
System.out.println(“Inside readAllLinesIntoOne”);
BufferedReader br = new BufferedReader(new FileReader(inputFile));
String line;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line.trim());
}
br.close();
return sb.toString();
}
}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.