-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathFileReader.java
More file actions
44 lines (37 loc) · 968 Bytes
/
Copy pathFileReader.java
File metadata and controls
44 lines (37 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Simple class for reading files as strings.
*
* @author Jeffery Russell
*/
public class FileReader
{
public static String readFile(String filePath)
{
String fileContent = new String();
try
{
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(filePath)));
String line;
while ((line = br.readLine()) != null)
{
fileContent = fileContent.concat(line);
}
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return fileContent;
}
public static void main(String[] args)
{
System.out.println("Test");
System.out.println(FileReader.readFile("./testData/data1.txt"));
}
}