정의

System 클래스는 운영체제와 상호작용하는 데 필요한 여러 기능을 모아놓은 클래스다. 표준입출력(키보드 입력과 모니터 출력), 환경변수 읽기, 시스템 프로퍼티 읽기, 현재 시각 읽기, 프로그램 실행 관련 기능(프로그램 종료, 가비지컬렉터 관련 기능), 보안 설정 기능(자바 프로그램의 보안 관리자 설정), 그리고 배열을 효율적으로 복사하는 기능까지 아우른다.

사용방법

System.in은 표준입력 처리에, System.out은 표준출력 처리에 쓰인다.

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
import java.io.IOException;
import java.util.Properties;

public class Main {
public static void main(String[] args) {
try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamReader(System.out))){

String str = br.readLine(); //라인 읽기
String path = System.getenv("..dir/../..path"); //환경변수
Properties properties = System.getProperties(); //프로퍼티

//가비지컬렉터 실행
System.gc();

//finalize method 빠른 호출
System.runFinalization();

//배열 Copy
int[] firstArr = {1, 2, 3, 4, 5};
int[] secondArr = new int[firstArr.length];
System.arraycopy(firstArr, 3, secondArr, 3, 1); //{0, 0, 0, 4, 0}

//현재시간
System.currentTimeMillis(); //1/1000초
}catch(IOException ioe){
System.err.print(ioe.getMessage());
}
}

@Override
protected void finalize(){
//객체삭제 시 시스템 자원 해제 가장 먼저 실행...
//....//
}
}