LoadRunner - Java - Read a File
Jump to navigation
Jump to search
String[] lines = new String[100]; String requestFile = "Request.xml"; FileReader fr = null; BufferedReader reader = null; try { fr = new FileReader(requestFile); } catch (Exception e) { System.out.println("Could not read XML file - " + requestFile + ": " + e.toString()); lr.abort(); } if (fr != null) { try { reader = new BufferedReader(fr); } catch (Exception e) { System.out.println("Could not create BufferedReader: " + e.toString()); lr.abort(); } String line = null; StringBuilder sb = new StringBuilder(); String eol = System.getProperty("line.separator"); try { while ((line = reader.readLine() ) != null ) { sb.append(line); sb.append(eol); } reader.close(); } catch (Exception e) { System.out.println("Could not create BufferedReader: " + e.toString()); lr.abort(); } finally { requestXml = sb.toString(); System.out.println("Request XML:\n\n" + requestXml); } }