-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileLog.java
More file actions
52 lines (46 loc) · 896 Bytes
/
Copy pathFileLog.java
File metadata and controls
52 lines (46 loc) · 896 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
45
46
47
48
49
50
51
52
import java.io.FileWriter;
import java.io.IOException;
public class FileLog{
private final static String LINE_SEPARATOR = System.getProperty("line.separator"); // for portability.
private String destName;
private FileWriter fw;
public FileLog(String destName){
this.destName = destName;
}
public boolean connect(){
if(destName==null){
return false;
}
try{
fw = new FileWriter(destName);
}catch(IOException ioe){
ioe.printStackTrace();
return false;
}
return true;
}
public boolean disconnect(){
if(fw==null){
return false;
}
try{
fw.close();
}catch(IOException ioe){
ioe.printStackTrace();
return false;
}
return true;
}
public boolean log(String msg){
if(fw==null){
return false;
}
try{
fw.write(msg + LINE_SEPARATOR);
}catch(IOException ioe){
ioe.printStackTrace();
return false;
}
return true;
}
}