Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 8ea3222

Browse files
authored
Merge pull request #33 from HPCToolkit/develop
Add missing file FileUtitlity.java
2 parents 1b1b0e1 + 018b8a2 commit 8ea3222

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package edu.rice.cs.hpcviewer.ui.util;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.io.PrintWriter;
7+
8+
public class FileUtility
9+
{
10+
/***
11+
* Read the content of the file
12+
* @param filename
13+
* @return String
14+
* @throws IOException
15+
*/
16+
public static String getFileContent(String filename) throws IOException {
17+
File file = new File(filename);
18+
if (!file.canRead())
19+
return "";
20+
21+
FileInputStream fis = new FileInputStream(file);
22+
byte[] data = new byte[(int) file.length()];
23+
fis.read(data);
24+
25+
String content = new String(data, "UTF-8");
26+
fis.close();
27+
28+
return content;
29+
}
30+
31+
32+
/****
33+
* Remove the content of the file without deleting it.
34+
*
35+
* @param filename
36+
* @throws IOException
37+
*/
38+
public static void clearFileContent(String filename) throws IOException {
39+
new PrintWriter(filename).close();
40+
}
41+
}

0 commit comments

Comments
 (0)