package ex0729;

import java.io.Console;

public class ConsoleEx {

	public static void main(String[] args) {
		// 콘솔 입력을 지원하는 클래스로 JDK 6이상 부터 가능. 이클립스에서는 테스트 불가.
		Console c = System.console();
		if( c==null) {
			System.out.println("Console을 지원하지 않습니다.");
			System.exit(0);
		}
		
		String id = c.readLine("%s", "ID : ");
		char[] pwd = c.readPassword("%s", "Password : ");
		
		String s = new String(pwd); // char[]을 String으로
		
		System.out.println("아이디 : " + id);
		System.out.println("패스워드 : " + s);

	}

}

위 소스는 이클립스로 실행이 안되기 때문에 cmd 창에서 확인해보았다.

패스워드를 입력할 때 보이지 않게끔 해주는 거 보려고 한 코드!

'쌍용강북교육센터 > 7월' 카테고리의 다른 글

Q 0729_Ex001~Ex002_List  (0) 2021.07.30
0729_Ex06~Ex09_system : Java API  (0) 2021.07.29
0729_Ex01~Ex05_Generic  (0) 2021.07.29
0728_Ex11~Ex17_generic : 제네릭  (0) 2021.07.29
0728_Ex01~Ex03_exception : 예외처리  (0) 2021.07.29

+ Recent posts