| ReadXml.java |
1 /** 2 * ReadXml.java 3 * @author Alexander Scheidl 4 * 5 * 6 * Class for Reading XML File from hard disk 7 * 8 * tested with files form 1 kb to 36 MB, depending on Resources Java 9 * needs for files with more than 10 MB "-Xmx256M" for more memory 10 * 11 */ 12 13 package testxml; 14 15 import java.io.*; 16 17 18 19 public class ReadXml { 20 21 /** XML String storage */ 22 private String xmlstring =""; 23 24 /** Creates a new instance of ReadXml */ 25 public ReadXml() { 26 } 27 28 29 /** 30 * 31 * @return Xml String 32 * 33 */ 34 public String getXmlString(){ 35 return this.xmlstring; 36 } 37 38 39 /** 40 * Reads file with help of the BufferedReader class into a StringBuffer 41 * and returns it into an String 42 * @param s String with the path to the file 43 * @throws FileNotFoundException if file not found error is returned. please not, in the unit test expections are not covered 44 * @throws IOException for all other file access errors 45 */ 46 public void doReading(String s){ 47 48 StringBuffer sb = new StringBuffer(); 49 String line; 50 FileReader fread = null; 51 try { 52 fread = new FileReader(s); 53 BufferedReader in = new BufferedReader(fread); 54 55 while((line = in.readLine()) != null){ // read every line until end 56 sb.append(line); 57 } 58 59 } catch (FileNotFoundException ex) { // exception handlling 60 ex.printStackTrace(); 61 } catch (IOException ex) { 62 ex.printStackTrace(); 63 } 64 65 this.xmlstring = sb.toString(); // set instance variable xmlstring 66 67 } 68 } 69