-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCreation.java
More file actions
84 lines (67 loc) · 1.73 KB
/
FileCreation.java
File metadata and controls
84 lines (67 loc) · 1.73 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package document;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class FileCreation {
String fileName="";
FileCreation()
{
try {
DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
String extension=dateFormat.format(date);
File file = new File("C:/sunil/filename_"+extension+".html");
this.fileName="C:/sunil/filename_"+extension+".html";
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("<html>");
bw.write("<h1>Test Case"+ extension+"</h1>");
bw.write("<table border=\"1\">");
bw.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
}
void addText(String message)
{
try {
File file = new File(fileName);
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bw = new BufferedWriter(fw);
bw.append("<tr>");
bw.append("<td>");
bw.append("No");
bw.append("</td>");
bw.append("<td>");
bw.append(message);
bw.append("</td>");
bw.append("</tr>");
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
void endText()
{
try {
File file = new File(fileName);
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bw = new BufferedWriter(fw);
bw.append("</table>");
bw.append("</html>");
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}