-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogFile.java
More file actions
57 lines (53 loc) · 1.57 KB
/
Copy pathLogFile.java
File metadata and controls
57 lines (53 loc) · 1.57 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* Created by sm-user on 13.11.2016.
*/
public class LogFile {
public int totalTest;
public int passed;
public int failed;
public double totalTime;
public File writeLogFile (String text) {
File file=new File("D://logFile.txt");
try
{
if(!file.exists()){
file.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
bw.write(text);
bw.write("\r\n");
bw.close();
} catch (IOException e)
{
e.printStackTrace();
}
return file;
}
public File writeResults (int totalTest, int passed, int failed, double totalTime){
File file=new File("D://logFile.txt");
try
{
if(!file.exists()){
file.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
bw.write("Total tests: " + totalTest);
bw.write("\r\n");
bw.write("Passed/Failed: " + passed + "/" + failed);
bw.write("\r\n");
bw.write("Total time: " + String.format("%.3f", totalTime));
bw.write("\r\n");
bw.write("Average time: " + String.format("%.3f", totalTime / totalTest));
bw.write("\r\n");
bw.close();
} catch (IOException e)
{
e.printStackTrace();
}
return file;
}
}