package gov.hhs.fha.nhinc.util; import java.io.FileReader; /** * String utilities... * * @author Les Westberg */ public class StringUtil { /** * This method reads the entire contents of a text file and returns the contents in * a string variable. * * @param sFileName The path and location of the text file. * @return The contents that was read in. */ public static String readTextFile(String sFileName) throws UtilException { String sText = ""; FileReader frTextFile = null; try { frTextFile = new FileReader(sFileName); char caBuf[] = new char[1024]; int iLen = 0; StringBuffer sbText = new StringBuffer(); while ((iLen = frTextFile.read(caBuf, 0, 1024)) != -1) { sbText.append(caBuf, 0, iLen); } sText = sbText.toString(); } catch (Exception e) { String sErrorMessage = "Failed to read text file: " + sFileName + ". Error: " + e.getMessage(); throw new UtilException(sErrorMessage, e); } finally { if (frTextFile != null) { try { frTextFile.close(); } catch (Exception e) { } } } return sText; } }