From 018b8a297242aadfc2c026341696e264bb6e2e1a Mon Sep 17 00:00:00 2001 From: "laksono@gmail.com" Date: Tue, 17 Nov 2020 09:55:30 -0600 Subject: [PATCH] Add missing file --- .../cs/hpcviewer/ui/util/FileUtility.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 edu.rice.cs.hpcviewer.ui/src/edu/rice/cs/hpcviewer/ui/util/FileUtility.java diff --git a/edu.rice.cs.hpcviewer.ui/src/edu/rice/cs/hpcviewer/ui/util/FileUtility.java b/edu.rice.cs.hpcviewer.ui/src/edu/rice/cs/hpcviewer/ui/util/FileUtility.java new file mode 100644 index 000000000..78803bb20 --- /dev/null +++ b/edu.rice.cs.hpcviewer.ui/src/edu/rice/cs/hpcviewer/ui/util/FileUtility.java @@ -0,0 +1,41 @@ +package edu.rice.cs.hpcviewer.ui.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintWriter; + +public class FileUtility +{ + /*** + * Read the content of the file + * @param filename + * @return String + * @throws IOException + */ + public static String getFileContent(String filename) throws IOException { + File file = new File(filename); + if (!file.canRead()) + return ""; + + FileInputStream fis = new FileInputStream(file); + byte[] data = new byte[(int) file.length()]; + fis.read(data); + + String content = new String(data, "UTF-8"); + fis.close(); + + return content; + } + + + /**** + * Remove the content of the file without deleting it. + * + * @param filename + * @throws IOException + */ + public static void clearFileContent(String filename) throws IOException { + new PrintWriter(filename).close(); + } +}