Created
December 15, 2023 11:31
-
-
Save ramyo564/a01a487c011f1a5255766418b0aac4b7 to your computer and use it in GitHub Desktop.
Mission_1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.util.Properties; | |
public class Main { | |
public static void main(String[] args) { | |
// 시스템 속성 가져오기 | |
Properties systemProperties = System.getProperties(); | |
// 저장할 파일명 | |
String fileName = "property.html"; | |
try (FileOutputStream outputStream = new FileOutputStream(fileName)) { | |
// HTML 헤더 작성 | |
String htmlHeader = "<html>" + | |
"<head><meta charset=\"UTF-8\"/><style>table {border-collapse: collapse; width: 100%;} th,td{border:solid 1px #000;}</style>" + | |
"<title>System Properties</title>" + | |
"</head>" + | |
"<body><h1>자바환경정보</h1><table border=\"1\"><tr><th>키</th><th>값</th></tr>"; | |
outputStream.write(htmlHeader.getBytes()); | |
// 시스템 속성을 파일에 쓰기 | |
systemProperties.forEach((key, value) -> { | |
try { | |
String htmlRow = "<tr><td>" + key + "</td><td>" + value + "</td></tr>"; | |
outputStream.write(htmlRow.getBytes()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
}); | |
// HTML 푸터 작성 | |
String htmlFooter = "</table></body></html>"; | |
outputStream.write(htmlFooter.getBytes()); | |
System.out.println("System properties saved to " + fileName); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment