Coverage details for umich.cac.util.FileUtil

LineHitsSource
1 package umich.cac.util;
2  
3 import java.io.*;
4 import java.util.logging.Level;
5 import java.util.logging.Logger;
6  
7 /**
8  * A collection of File utilities
9  *
10  * @author rmach@umich.edu
11  * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/util/FileUtil.java,v 1.2 2003/04/08 22:06:09 rodmach Exp $
12  * @created December 29, 2002
13  */
140public class FileUtil {
15  
16     //logger
176    private static Logger logger = Logger.getLogger(FileUtil.class.getName());
18  
19  
20     /**
21      * Read a file and return it as a String, or null if can't read
22      *
23      * @param filename name of the file
24      * @return String filename contents as a String
25      */
26  
27     public static String getFile(String filename) {
28  
29         try {
3030            BufferedReader is = new BufferedReader(new FileReader(filename));
3130            StringBuffer sb = new StringBuffer();
3230            char[] b = new char[1024];
33             int n;
34  
3563            while ((n = is.read(b)) > 0) {
3633                sb.append(b, 0, n);
37             }
38  
3930            is.close();
40  
4130            return sb.toString();
420        } catch (Exception e) {
430            logger.log(Level.SEVERE, "unable to read file", e);
440            return null;
45         }
46     }
47 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.