1 23 24 package com.rift.coad.lib.common; 26 27 import com.rift.coad.lib.common.*; 29 import java.io.File ; 30 import java.io.FileReader ; 31 32 37 public class TextFile { 38 39 private String textDocument = null; 41 42 47 public TextFile(File targetFile) throws CommonException { 48 try { 49 FileReader fileReader = new FileReader (targetFile); 50 char[] buffer = new char[1024]; 51 StringBuffer stringBuffer = new StringBuffer (); 52 int length = 0; 53 while ((length = fileReader.read(buffer)) != -1) { 54 stringBuffer.append(buffer,0,length); 55 } 56 textDocument = stringBuffer.toString(); 57 fileReader.close(); 58 } catch (Exception ex) { 59 throw new CommonException("Failed to read in the text document [" + 60 targetFile.getPath() + "] because : " + ex.getMessage(), 61 ex); 62 } 63 } 64 65 66 71 public String getTextDocument() { 72 return textDocument; 73 } 74 } 75 | Popular Tags |