Skip to content

Commit

Permalink
Merge pull request #33 from HPCToolkit/develop
Browse files Browse the repository at this point in the history
Add missing file FileUtitlity.java
  • Loading branch information
laksono authored Nov 17, 2020
2 parents 1b1b0e1 + 018b8a2 commit 8ea3222
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 8ea3222

Please sign in to comment.