-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileStore.java
More file actions
33 lines (27 loc) · 780 Bytes
/
Copy pathFileStore.java
File metadata and controls
33 lines (27 loc) · 780 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.preisinger.util;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.File;
import java.io.IOException;
public class FileStore {
public static final String DEFAULT_DIR = "./output/";
public void write(final String fileName, String dir, final String content) {
if(fileName == null || content == null){
throw new IllegalArgumentException("fileName and content must not be null");
}
if(dir != null){
new File(dir).mkdirs();
} else {
new File(DEFAULT_DIR).mkdirs();
dir = DEFAULT_DIR;
}
String path = dir + fileName;
try {
BufferedWriter out = new BufferedWriter(new FileWriter(new File(path)));
out.write(content);
out.close();
} catch (IOException e){
System.out.println(e.getMessage());
}
}
}