Skip to content

Instantly share code, notes, and snippets.

@zhyunk
Created April 10, 2023 13:47
Show Gist options
  • Save zhyunk/0e31b474bc33e74de7cfc8037fa2a8c1 to your computer and use it in GitHub Desktop.
Save zhyunk/0e31b474bc33e74de7cfc8037fa2a8c1 to your computer and use it in GitHub Desktop.
Mission1 "깜짝과제"
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
// 23.04.10
// 김지현
public class Main {
final String FILE_NAME = "property.html";
final String PAGE_TITLE = "자바 환경정보";
final String COLUMN_TITLE1 = "키";
final String COLUMN_TITLE2 = "값";
StringBuffer sb = new StringBuffer();
public static void main(String[] args) {
new Main().makeHtmlFile();
}
// HTML 파일 생성
private void makeHtmlFile() {
if (sb == null) sb = new StringBuffer();
makeHtmlHeader();
makeHtmlBody();
makeHtmlFooter();
try {
File file = new File(FILE_NAME);
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(sb.toString());
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// HTML Header 작성
private void makeHtmlHeader() {
sb.append("<!doctype html> \n");
sb.append("<html> \n");
sb.append("<head> \n");
sb.append(" <meta charset=\"utf-8\"> \n");
sb.append(" <title>");
sb.append(PAGE_TITLE);
sb.append("</title> \n");
sb.append(" <style> \n");
sb.append(" table { border-collapse: collapse; width: 100%; }\n");
sb.append(" th, td { border: solid 1px #000; } \n");
sb.append(" </style> \n");
sb.append("</head> \n");
sb.append("<body> \n");
}
// HTML Body 작성
private void makeHtmlBody() {
sb.append(" <h1>");
sb.append(PAGE_TITLE);
sb.append("</h1>\n");
makeHtmlTable();
}
// HTML Body - Table 작성
private void makeHtmlTable() {
sb.append(" <table> \n");
sb.append(" <thead> \n");
sb.append(" <tr> \n");
sb.append(" <th>");
sb.append(COLUMN_TITLE1);
sb.append("</th> \n");
sb.append(" <th>");
sb.append(COLUMN_TITLE2);
sb.append("</th> \n");
sb.append(" </tr> \n");
sb.append(" </thead> \n");
sb.append(" <tbody> \n");
for (Object k: System.getProperties().keySet()) {
String key = k.toString();
String value = System.getProperty(key);
sb.append("<tr>");
sb.append(" <td>");
sb.append(key);
sb.append("</td>");
sb.append(" <td>");
sb.append(value);
sb.append("</td>");
sb.append("</tr>\n");
}
sb.append(" </tbody>\n");
sb.append(" </table> \n");
}
// HTML Footer 작성
private void makeHtmlFooter() {
sb.append("</body> \n");
sb.append("</html> \n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment