本文整理了Java中java.io.Console.readLine()
方法的一些代码示例,展示了Console.readLine()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Console.readLine()
方法的具体详情如下:
包路径:java.io.Console
类名称:Console
方法名:readLine
[英]Reads a line from the console.
[中]从控制台读取一行。
代码示例来源:origin: stackoverflow.com
public class ConsoleReadingDemo {
public static void main(String[] args) {
// ====
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter user name : ");
String username = null;
try {
username = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("You entered : " + username);
// ===== In Java 5, Java.util,Scanner is used for this purpose.
Scanner in = new Scanner(System.in);
System.out.print("Please enter user name : ");
username = in.nextLine();
System.out.println("You entered : " + username);
// ====== Java 6
Console console = System.console();
username = console.readLine("Please enter user name : ");
System.out.println("You entered : " + username);
}
}
代码示例来源:origin: apache/storm
System.out.println("Need at least 2 arguments, but have " + Integer.toString(args.length));
System.out.println("migrate <local_blobstore_dir> <hdfs_blobstore_path> <hdfs_principal> <keytab>");
System.out.println("Migrates blobs from LocalFsBlobStore to HdfsBlobStore");
System.out.println("Example: migrate '/srv/storm' 'hdfs://some-hdfs-namenode:8080/srv/storm/my-storm-blobstore' 'stormUser/my-nimbus-host.example.com@STORM.EXAMPLE.COM' '/srv/my-keytab/stormUser.kt'");
System.exit(1);
System.out.println("Going to delete everything in HDFS, then copy all local blobs to HDFS. Continue? [Y/n]");
String resp = System.console().readLine().toLowerCase().trim();
if (!(resp.equals("y") || resp.equals(""))) {
System.out.println("Not copying blobs. Exiting. [" + resp.toLowerCase().trim() + "]");
代码示例来源:origin: awsdocs/aws-doc-sdk-examples
System.out.println(USAGE);
System.exit(1);
pause = true;
} else {
System.out.println("Unknown argument: " + args[cur_arg]);
System.out.println(USAGE);
System.exit(1);
System.out.println("The local path already exists: " + local_path);
String a = System.console().readLine("Do you want to overwrite it anyway? (yes/no): ");
if (!a.toLowerCase().equals("yes")) {
System.out.println("Aborting download!");
代码示例来源:origin: wildfly/wildfly
System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
System.exit(1);
.readLine(SecurityLogger.ROOT_LOGGER.enterEncryptionDirectory() + " ");
keystoreURL = console.readLine(SecurityLogger.ROOT_LOGGER.enterKeyStoreURL() + " ");
salt = console.readLine(SecurityLogger.ROOT_LOGGER.enterSalt() + " ");
String ic = console.readLine(SecurityLogger.ROOT_LOGGER.enterIterationCount() + " ");
iterationCount = Integer.parseInt(ic);
vaultNISession = new VaultSession(keystoreURL, new String(keystorePasswd), encDir, salt, iterationCount, true);
keystoreAlias = console.readLine(SecurityLogger.ROOT_LOGGER.enterKeyStoreAlias() + " ");
System.out.println(SecurityLogger.ROOT_LOGGER.initializingVault());
vaultNISession.startVaultSession(keystoreAlias);
vaultNISession.vaultConfigurationDisplay();
System.out.println(SecurityLogger.ROOT_LOGGER.vaultInitialized());
System.out.println(SecurityLogger.ROOT_LOGGER.handshakeComplete());
代码示例来源:origin: wildfly/wildfly
System.err.println(SecurityLogger.ROOT_LOGGER.noConsole());
System.exit(1);
String commandStr = SecurityLogger.ROOT_LOGGER.interactionCommandOptions();
System.out.println(commandStr);
int choice = in.nextInt();
switch (choice) {
case 0:
System.out.println(SecurityLogger.ROOT_LOGGER.taskStoreSecuredAttribute());
char[] attributeValue = VaultInteractiveSession.getSensitiveValue(SecurityLogger.ROOT_LOGGER.interactivePromptSecureAttributeValue(), SecurityLogger.ROOT_LOGGER.interactivePromptSecureAttributeValueAgain());
String vaultBlock = null;
vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
vaultBlock = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptVaultBlock());
attributeName = console.readLine(SecurityLogger.ROOT_LOGGER.interactivePromptAttributeName());
代码示例来源:origin: stackoverflow.com
import java.io.Console;
public class Test {
public static void main(String[] args) throws Exception {
Console console = System.console();
if (console == null) {
System.out.println("Unable to fetch console");
return;
}
String line = console.readLine();
console.printf("I saw this line: %s", line);
}
}
代码示例来源:origin: biezhi/learn-java8
public static void main(String[] args) {
java.io.Console console = System.console();
if (console != null) {
String user = new String(console.readLine(" Enter User: ", new Object[0]));
String pwd = new String(console.readPassword(" Enter Password: ", new Object[0]));
console.printf(" User name is:%s ", new Object[]{user});
console.printf(" Password is:%s ", new Object[]{pwd});
} else {
System.out.println(" No Console! ");
}
}
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Looks up words in the index that the user enters into the console.
*/
public void lookupWords() {
System.out.println("Entering word lookup mode.");
System.out
.println("To index a directory, add an input path argument when you run this command.");
System.out.println();
Console console = System.console();
if (console == null) {
System.err.println("No console.");
System.exit(1);
}
while (true) {
String words =
console.readLine("Enter word(s) (comma-separated, leave blank to exit): ").trim();
if (words.equals("")) {
break;
}
index.printLookup(Splitter.on(',').split(words));
}
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Exercises the methods defined in this class.
* <p>
* <p>Assumes that you are authenticated using the Google Cloud SDK (using
* {@code gcloud auth application-default-login}).
*/
public static void main(String[] args) throws Exception {
Snippets snippets = new Snippets();
System.out.println("Stackdriver Monitoring snippets");
System.out.println();
printUsage();
while (true) {
String commandLine = System.console().readLine("> ");
if (commandLine.trim().isEmpty()) {
break;
}
try {
snippets.handleCommandLine(commandLine);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
printUsage();
}
}
System.out.println("exiting");
System.exit(0);
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Exercises the methods defined in this class.
*
* <p>Assumes that you are authenticated using the Google Cloud SDK (using
* {@code gcloud auth application-default login}).
*/
public static void main(String[] args) throws Exception {
TaskList taskList = new TaskList();
System.out.println("Cloud Datastore Task List");
System.out.println();
printUsage();
while (true) {
String commandLine = System.console().readLine("> ");
if (commandLine.trim().isEmpty()) {
break;
}
try {
taskList.handleCommandLine(commandLine);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
printUsage();
}
}
System.out.println("exiting");
System.exit(0);
}
代码示例来源:origin: stackoverflow.com
String pref = null;
if (p.equals("Y")) {//offen3
System.out.println("Gib deinen Prefix an!");
pref = System.console().readLine();
}//zu3
代码示例来源:origin: stackoverflow.com
do {
String input = System.console().readLine();
//Change playerControls(KeyEvent e) to playerControls(String e)
player.playerControls(input);
validInput = true;
System.out.println("!!!!!!!!!!enter the intro story here!!!!!!!!!");
} while (gameRun);
代码示例来源:origin: stackoverflow.com
if (s.equals ("Y")) {//offen4
System.out.println("Gib deinen Suffix an!");
suff = System.console().readLine();
} else {
// some backup mechanism like System.exit(0);
// so that it doesn't pose a problem later.
代码示例来源:origin: org.apache.knox/gateway-shell
protected String collectClearCredential(String prompt) {
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}
String username = c.readLine(prompt);
value = username;
return value;
}
代码示例来源:origin: xipki/xipki
public static String readLineFromConsole(String prompt) {
Console console = System.console();
if (console == null) {
throw new IllegalStateException("No console is available for input");
}
if (prompt != null) {
System.out.println(prompt);
}
return console.readLine();
}
代码示例来源:origin: org.xipki/util
public static String readLineFromConsole(String prompt) {
Console console = System.console();
if (console == null) {
throw new IllegalStateException("No console is available for input");
}
if (prompt != null) {
System.out.println(prompt);
}
return console.readLine();
}
代码示例来源:origin: IanDarwin/javasrc
public static void main(String[] args) {
String name = System.console().readLine("What is your name?");
System.out.println("Hello, " + name.toUpperCase());
}
}
代码示例来源:origin: stackoverflow.com
public class OddSum1 {
public OddSum1() {
}
public static void main(String[] args) {
int OddLimit = Integer.parseInt(System.console().readLine());
int sum = 0;
for (int i = 1; i <= OddLimit; i += 2)
sum += i;
System.out.println("The sum of odd numbers from 1 to " + OddLimit + " is " + sum);
}
}
代码示例来源:origin: stackoverflow.com
Console cons = System.console();
if (cons != null) {
String line = cons.readLine();
System.out.println(line);
} else {
System.out.println("no console");
}
代码示例来源:origin: stackoverflow.com
Console console = System.console();
if (console != null) {
String line = null;
while ((line = console.readLine()) != null) {
processLine(line.trim());
}
} else {
System.out.println("No console available!!");
}
内容来源于网络,如有侵权,请联系作者删除!