-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from HPCToolkit/develop
Add missing file FileUtitlity.java
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
edu.rice.cs.hpcviewer.ui/src/edu/rice/cs/hpcviewer/ui/util/FileUtility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |