本文整理了Java中java.io.Console.printf()
方法的一些代码示例,展示了Console.printf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Console.printf()
方法的具体详情如下:
包路径:java.io.Console
类名称:Console
方法名:printf
[英]Equivalent to format(format, args).
[中]等效于格式(格式,args)。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public Console printf(String format, Object... args) {
return delegate.printf(format, args);
}
代码示例来源:origin: web3j/web3j
@Override
public void printf(String format, Object... args) {
console.printf(format, args);
}
代码示例来源:origin: stackoverflow.com
import java.io.Console;
public class Main {
public void passwordExample() {
Console console = System.console();
if (console == null) {
System.out.println("Couldn't get Console instance");
System.exit(0);
}
console.printf("Testing password%n");
char passwordArray[] = console.readPassword("Enter your secret password: ");
console.printf("Password entered was: %s%n", new String(passwordArray));
}
public static void main(String[] args) {
new Main().passwordExample();
}
}
代码示例来源:origin: btraceio/btrace
@Override
public void handle(Signal sig) {
try {
con.printf("Please enter your option:\n");
con.printf("\t1. exit\n\t2. send an event\n\t3. send a named event\n\t4. flush console output\n");
con.flush();
String option = con.readLine();
break;
case "3":
con.printf("Please enter the event name: ");
String name = con.readLine();
if (name != null) {
break;
default:
con.printf("invalid option!\n");
break;
代码示例来源:origin: hierynomus/sshj
@Override
protected boolean hostKeyUnverifiableAction(String hostname, PublicKey key) {
final KeyType type = KeyType.fromKey(key);
console.printf("The authenticity of host '%s' can't be established.\n" +
"%s key fingerprint is %s.\n", hostname, type, SecurityUtils.getFingerprint(key));
String response = console.readLine("Are you sure you want to continue connecting (yes/no)? ");
while (!(response.equalsIgnoreCase(YES) || response.equalsIgnoreCase(NO))) {
response = console.readLine("Please explicitly enter yes/no: ");
}
if (response.equalsIgnoreCase(YES)) {
try {
entries().add(new HostEntry(null, hostname, KeyType.fromKey(key), key));
write();
console.printf("Warning: Permanently added '%s' (%s) to the list of known hosts.\n", hostname, type);
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
return false;
}
代码示例来源:origin: hierynomus/sshj
@Override
protected boolean hostKeyChangedAction(String hostname, PublicKey key) {
final KeyType type = KeyType.fromKey(key);
final String fp = SecurityUtils.getFingerprint(key);
final String path = getFile().getAbsolutePath();
console.printf(
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" +
"@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\n" +
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" +
"IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\n" +
"Someone could be eavesdropping on you right now (man-in-the-middle attack)!\n" +
"It is also possible that the host key has just been changed.\n" +
"The fingerprint for the %s key sent by the remote host is\n" +
"%s.\n" +
"Please contact your system administrator or" +
"add correct host key in %s to get rid of this message.\n",
type, fp, path);
return false;
}
代码示例来源:origin: stackoverflow.com
class Main {
public static void main(String[] args) throws InterruptedException {
String[] spinner = new String[] {"\u0008/", "\u0008-", "\u0008\\", "\u0008|" };
Console console = System.console();
console.printf("|");
for (int i = 0; i < 1000; i++) {
Thread.sleep(150);
console.printf("%s", spinner[i % spinner.length]);
}
}
}
代码示例来源: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: 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: stackoverflow.com
public class A {
public void method() {
int i = 0; // note: this is WRONG code
doStuff(new Action() {
public void doAction() {
Console.printf(i); // or whatever
}
});
i = 4; // A
// B
i = 5; // C
}
}
代码示例来源:origin: org.apache.karaf.tooling/karaf-maven-plugin
@Override
public void welcome(ClientSession s, String banner, String lang) {
console.printf(banner);
}
@Override
代码示例来源:origin: org.openksavi.sponge/sponge-core
@Override
public void print(String text) {
if (console != null) {
console.printf(text);
} else {
System.out.print(text);
}
}
代码示例来源:origin: org.apache.kerby/has-tool
private String getReply(Console console, String prompt) {
console.printf(prompt);
String line = console.readLine();
return line;
}
}
代码示例来源:origin: org.onap.aaf.cadi/cadi-core
@Override
public void printf(String fmt, Object... args) {
System.console().printf(fmt, args);
}
}
代码示例来源:origin: stackoverflow.com
public class PrintUnicode {
public static void main(String[] args) {
System.console().printf("Olá Mundo!");
}
}
代码示例来源:origin: net.shibboleth.idp/idp-installer
/**
* Constructor.
*
*/
public PasswordHandler() {
System.console().printf("Calling Deprecated class " + this.getClass().getName() + "\n");
}
代码示例来源:origin: documents4j/documents4j
private static void sayHello(IConverter converter, Logger logger, Console console) {
console.printf("Welcome to the documents4j client!%n");
boolean operational = converter.isOperational();
if (operational) {
logger.info("Converter {} is operational", converter);
} else {
logger.warn("Converter {} is not operational", converter);
}
}
代码示例来源:origin: beryx/text-io
@Override
public void rawPrint(String message) {
console.printf(message);
console.flush();
}
代码示例来源:origin: camelinaction/camelinaction2
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
Console console = System.console();
console.printf("Please enter your Rider Auto Parts password: ");
char[] passwordChars = console.readPassword();
String passwordString = new String(passwordChars);
pc.setPassword(passwordString);
}
}
代码示例来源:origin: protegeproject/webprotege
public void createAdministratorAccount() throws IOException {
console.printf("Please enter a user name for the administrator:\n");
String userName = console.readLine();
console.printf("Please enter an email address for the administrator:\n");
String emailAddress = console.readLine();
String password = getPassword(console);
createAdministratorAccount(userName, emailAddress, password);
accessManager.setAssignedRoles(Subject.forUser(userName),
ApplicationResource.get(),
Collections.singleton(BuiltInRole.SYSTEM_ADMIN.getRoleId()));
console.printf("You have successfully set up the administrator account.\n");
}
内容来源于网络,如有侵权,请联系作者删除!