コード例 #1
0
 private static String writeFile(File file, String content, boolean append) {
   PrintWriter out = null;
   try {
     out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, append), "UTF-8"));
     out.print(content);
     return null;
   } catch (IOException ex) {
     return ex.getMessage();
   } finally {
     FileUtilities.close(out);
   }
 }
コード例 #2
0
 /**
  * Reads all the lines from the named file into a string array. Throws a RuntimeException on
  * failure.
  */
 public static String[] readLinesFromFile(String filename) {
   ArrayList<String> result = new ArrayList<String>();
   LineNumberReader in = null;
   try {
     File file = FileUtilities.fileFromString(filename);
     in = new LineNumberReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
     String line;
     while ((line = in.readLine()) != null) {
       result.add(line);
     }
     return result.toArray(new String[result.size()]);
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   } finally {
     FileUtilities.close(in);
   }
 }