1 package org.mmbase.bridge.jsp.taglib.util; 2 import java.io.*; 3 import org.w3c.dom.*; 4 import org.mmbase.util.Casting; 5 6 13 public class ReadFile { 14 public static Document readExample(String actualFileName) { 15 return Casting.toXML("<example><![CDATA[" + contents(actualFileName) + "]]></example>"); 16 } 17 18 public static String contents(String actualFileName) { 19 FileReader in = null; 20 try { 21 in = new FileReader(actualFileName); 22 } catch (FileNotFoundException e) { 23 return "File '" + actualFileName + "' not found.\n"; 24 } 25 StringWriter out = new StringWriter(); 26 27 char[] buffer = new char[4096]; 28 int numchars; 29 try { 30 while((numchars = in.read(buffer)) != -1) { 31 out.write(buffer, 0, numchars); 32 } 33 out.close(); 34 } catch (IOException e) { 35 return "IO Error reading file '" + actualFileName + "'.\n"; 36 } 37 String returnContents = out.toString(); 38 return returnContents.trim(); 39 } 40 } 41 | Popular Tags |