-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
33 lines (28 loc) · 971 Bytes
/
ReadFile.java
File metadata and controls
33 lines (28 loc) · 971 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
package com.leetcode.utils;
import com.leetcode.problems.Problem239;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class ReadFile {
public static void main(String[] args) throws IOException {
String path = Problem239.class.getResource("data.txt").getPath();
FileReader data = new FileReader(new File(path));
StringBuilder sb = new StringBuilder();
char[] buffer = new char[1024*8];
while (data.read(buffer)!=-1)
{
sb.append(buffer);
}
}
public static String readFile(String fileName) throws IOException {
String path = Problem239.class.getResource(fileName).getPath();
FileReader data = new FileReader(new File(path));
StringBuilder sb = new StringBuilder();
char[] buffer = new char[8];
while (data.read(buffer)!=-1)
{
sb.append(buffer);
}
return sb.toString();
}
}