-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFilesMu.java
More file actions
42 lines (36 loc) · 1.03 KB
/
FilesMu.java
File metadata and controls
42 lines (36 loc) · 1.03 KB
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
package mu;
import com.google.common.base.Preconditions;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
/**
* File handling helpers
*/
public class FilesMu {
/**
* write content to file with default charset, omitting the previous content if any
*/
public static void writeFile(String contentToWrite, String fileName) {
Preconditions.checkNotNull(contentToWrite);
Preconditions.checkNotNull(fileName);
try {
Files.write(contentToWrite, new File(fileName), Charset.defaultCharset());
} catch (IOException e) {
throw ExceptionsMu.asUnchecked(e);
}
}
/**
* read file content with default charset
* @return list of lines of the content
*/
public static List<String> readFile(String fileName) {
Preconditions.checkNotNull(fileName);
try {
return Files.readLines(new File(fileName), Charset.defaultCharset());
} catch (IOException e) {
throw ExceptionsMu.asUnchecked(e);
}
}
}