- 전체
- JAVA 일반
- JAVA 수학
- JAVA 그래픽
- JAVA 자료구조
- JAVA 인공지능
- JAVA 인터넷
- Java Framework
- Java GUI (AWT,SWING,SWT,JFACE)
- SWT and RCP (web RAP/RWT)[eclipse], EMF
I/O from the Command Line
2015.07.05 20:28
I/O from the Command LineA program is often run from the command line and interacts with the user in the command line environment. The Java platform supports this kind of interaction in two ways: through the Standard Streams and through the Console. Standard StreamsStandard Streams are a feature of many operating systems. By default, they read input from the keyboard and write output to the display. They also support I/O on files and between programs, but that feature is controlled by the command line interpreter, not the program. The Java platform supports three Standard Streams: Standard Input, accessed through You might expect the Standard Streams to be character streams, but, for historical reasons, they are byte streams. By contrast, InputStreamReader cin = new InputStreamReader(System.in); The ConsoleA more advanced alternative to the Standard Streams is the Console. This is a single, predefined object of type Before a program can use the Console, it must attempt to retrieve the Console object by invoking The Console object supports secure password entry through its The
import java.io.Console;
import java.util.Arrays;
import java.io.IOException;
public class Password {
public static void main (String args[]) throws IOException {
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}
String login = c.readLine("Enter your login: ");
char [] oldPassword = c.readPassword("Enter your old password: ");
if (verify(login, oldPassword)) {
boolean noMatch;
do {
char [] newPassword1 = c.readPassword("Enter your new password: ");
char [] newPassword2 = c.readPassword("Enter new password again: ");
noMatch = ! Arrays.equals(newPassword1, newPassword2);
if (noMatch) {
c.format("Passwords don't match. Try again.%n");
} else {
change(login, newPassword1);
c.format("Password for %s changed.%n", login);
}
Arrays.fill(newPassword1, ' ');
Arrays.fill(newPassword2, ' ');
} while (noMatch);
}
Arrays.fill(oldPassword, ' ');
}
// Dummy change method.
static boolean verify(String login, char[] password) {
// This method always returns
// true in this example.
// Modify this method to verify
// password according to your rules.
return true;
}
// Dummy change method.
static void change(String login, char[] password) {
// Modify this method to change
// password according to your rules.
}
}
The
|
[출처] https://docs.oracle.com/javase/tutorial/essential/io/cl.html
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 7 |
REST with Java (JAX-RS) using Jersey - Tutorial
| 졸리운_곰 | 2015.07.16 | 434 |
| 6 |
Tutorial – REST API design and implementation in Java with Jersey and Spring
| 졸리운_곰 | 2015.07.16 | 830 |
| 5 | 12.2. Using REST in Java | 졸리운_곰 | 2015.07.16 | 230 |
| 4 | JAVA Telnet 프로그램 코드 | 졸리운_곰 | 2015.07.12 | 915 |
| 3 | swt java xulrunner 3.6 캐쉬 비우기 : html 깨짐 | 졸리운_곰 | 2015.04.27 | 339 |
| 2 | JAVA SWT XULRUNNER 브라우저 target=_black 멀티 윈도우 표시 | 졸리운_곰 | 2015.04.20 | 401 |
| 1 | NetStat call and get result text in Java | 졸리운_곰 | 2014.02.25 | 903 |

