반응형

 

https://gist.github.com/parkground/833047947f89f534326d4f3f036ac137

 

[Zero-base] 2주차 과제 (JavaSystemProperty.java)

[Zero-base] 2주차 과제 (JavaSystemProperty.java). GitHub Gist: instantly share code, notes, and snippets.

gist.github.com


import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Enumeration;

public class JavaSystemProperty {
    public static void main(String[] args) {

        /* 불러온 문자열을 저장할 경로와 html 파일 이름  지정 */
        String fileName = "c:\\java-system-property.html";

        /* 파일에 텍스트를 입력하는 부분 */
        try {
            File file = new File(fileName);
            BufferedWriter writer = new BufferedWriter(new FileWriter(file));

            /* html 파일의 head에서 table 스타일 지정 */
            writer.write("<!doctype html>\r\n<html lang=\"ko\">\r\n");
            writer.write("<head>\r\n    <meta charset=\"UTF-8\"/>\r\n  <style>\r\n");
            writer.write("    table { border: 1px; border-collapse: collapse; width: 100%; text-align: left; }\r\n");
            writer.write("    th, td { border: 1px solid #000; }\r\n  </style>\r\n</head>\r\n");
            writer.write("<body>\r\n  <h1>&#51088;&#48148; &#54872;&#44221;&#51221;&#48372;</h1>\r\n  <table>\r\n");
            writer.write("    <tr>\r\n      <th align=center>&#53412;</th>\r\n      <th></th>\r\n    </tr>\r\n");

            /* 자바 시스템 속성 값을 출력하는 부분 */
            Properties props = System.getProperties();
            Enumeration<Object> enumm = props.keys();
            while (enumm.hasMoreElements()) {

                /* 개별 항목을 key와 value로 불러옴 */
                String key = (String) enumm.nextElement();
                String value = (String) props.get(key);

                /* 불러온 값을 html 테이블 형식에 맞게 출력 */
                writer.write("    <tr>\r\n      <th>" + key + "</th>\r\n");
                writer.write("      <th>" + value + "</th>\r\n    </tr>\r\n");
            }

            /* htmle 파일의 끝 부분 */
            writer.write("  </table>\r\n</body>\r\n</html>\r\n");

            /* 파일 쓰기 함수 종료 */
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 


 

반응형

+ Recent posts