Line | Hits | Source |
---|---|---|
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 | */ | |
14 | 0 | public class FileUtil { |
15 | ||
16 | //logger | |
17 | 6 | 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 { | |
30 | 30 | BufferedReader is = new BufferedReader(new FileReader(filename)); |
31 | 30 | StringBuffer sb = new StringBuffer(); |
32 | 30 | char[] b = new char[1024]; |
33 | int n; | |
34 | ||
35 | 63 | while ((n = is.read(b)) > 0) { |
36 | 33 | sb.append(b, 0, n); |
37 | } | |
38 | ||
39 | 30 | is.close(); |
40 | ||
41 | 30 | return sb.toString(); |
42 | 0 | } catch (Exception e) { |
43 | 0 | logger.log(Level.SEVERE, "unable to read file", e); |
44 | 0 | return null; |
45 | } | |
46 | } | |
47 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |