source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Common/NhincLib/src/gov/hhs/fha/nhinc/util/StringUtil.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 1.5 KB
Line 
1package gov.hhs.fha.nhinc.util;
2
3import java.io.FileReader;
4
5/**
6 * String utilities...
7 *
8 * @author Les Westberg
9 */
10public class StringUtil
11{
12 /**
13 * This method reads the entire contents of a text file and returns the contents in
14 * a string variable.
15 *
16 * @param sFileName The path and location of the text file.
17 * @return The contents that was read in.
18 */
19 public static String readTextFile(String sFileName)
20 throws UtilException
21 {
22 String sText = "";
23 FileReader frTextFile = null;
24
25 try
26 {
27 frTextFile = new FileReader(sFileName);
28 char caBuf[] = new char[1024];
29 int iLen = 0;
30 StringBuffer sbText = new StringBuffer();
31 while ((iLen = frTextFile.read(caBuf, 0, 1024)) != -1)
32 {
33 sbText.append(caBuf, 0, iLen);
34 }
35
36 sText = sbText.toString();
37 }
38 catch (Exception e)
39 {
40 String sErrorMessage = "Failed to read text file: " + sFileName + ". Error: " + e.getMessage();
41 throw new UtilException(sErrorMessage, e);
42 }
43 finally
44 {
45 if (frTextFile != null)
46 {
47 try
48 {
49 frTextFile.close();
50 }
51 catch (Exception e)
52 {
53
54 }
55 }
56 }
57
58 return sText;
59 }
60}
Note: See TracBrowser for help on using the repository browser.