LoadRunner - Java - Read a File

From PeformIQ Upgrade
Revision as of 15:53, 20 January 2016 by PeterHarding (talk | contribs) (Created page with " <pre> String[] lines = new String[100]; String requestFile = "Request.xml"; FileReader fr = null; BufferedReader reader = null; try { fr = new FileReader(requestFi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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);
    	}
}