當前位置: 首頁>>代碼示例>>Java>>正文


Java Console.format方法代碼示例

本文整理匯總了Java中java.io.Console.format方法的典型用法代碼示例。如果您正苦於以下問題:Java Console.format方法的具體用法?Java Console.format怎麽用?Java Console.format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.Console的用法示例。


在下文中一共展示了Console.format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readPasswordFromConsole

import java.io.Console; //導入方法依賴的package包/類
/**
 * Prompts the user for the password on the console
 * 
 * @param user
 *            the username
 * 
 * @return the password
 * 
 * @throws Exception
 */
private static String readPasswordFromConsole(String user) throws Exception {
	Console c = System.console();
	String password = "";

	if (c == null) {
		System.err.println("No console.");
		System.out.println(String.format("You are logging in as: " + user + "\n"));
		System.out.print(String.format("Enter the password of that user account: "));

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		password = br.readLine();
		System.out.println("");
	}
	else {
		c.format("You are logging in as: " + user + "\n");
		char[] passwordChar = c.readPassword("Enter the password of that user account: ");
		password = new String(passwordChar);
		System.out.println("");
	}

	return new String(password);
}
 
開發者ID:hpclab,項目名稱:TheMatrixProject,代碼行數:33,代碼來源:IadCreator.java

示例2: run

import java.io.Console; //導入方法依賴的package包/類
@Override
public void run() {
	try {
		CONSOLE_LOCK.lockInterruptibly();
	} catch (InterruptedException e) {
		return; // don't need to login anymore -- promise was cancelled
	}
	try {
		String user = factoryUser;
		String password = factoryPassword;
		Console console = System.console();
		if (console == null) {
			Scanner scanner = new Scanner(System.in);
			System.out.println(reason);
			if (user.isEmpty()) {
				System.out.print(USER);
				user = scanner.nextLine();
			}
			if (password.isEmpty()) {
				System.out.print(PASSWORD);
				password = scanner.nextLine();
			}
		} else {
			console.format("%s%n", reason);
			if (user.isEmpty())
				user = console.readLine(USER);
			if (password.isEmpty())
				password = String.valueOf(console.readPassword(PASSWORD));
		}
		done(AuthToken.createBasicToken(user, password));
	} finally {
		CONSOLE_LOCK.unlock();
	}
}
 
開發者ID:Devexperts,項目名稱:QD,代碼行數:35,代碼來源:ConsoleLoginHandlerFactory.java

示例3: main

import java.io.Console; //導入方法依賴的package包/類
public static void main( String[] args ) {
    String nome = "";
    Console c = System.console();
    char[] senha = c.readPassword();

    for ( char ch : senha ) {
        c.format( "%c" , ch );
    }
    c.format( "\n" );

    while ( true ) {
        nome = c.readLine( "%s" , "entrada?: " );
        c.format( "saida: %s \n" , fazerAlgo( nome ) );
    }
}
 
開發者ID:juliocnsouzadev,項目名稱:ocpjp,代碼行數:16,代碼來源:NewConsole.java

示例4: waitForEnter

import java.io.Console; //導入方法依賴的package包/類
private static void waitForEnter() {
	Console c = System.console();
	if (c != null) {

		c.format("\nPress ENTER to proceed.\n");
		c.readLine();
	}
}
 
開發者ID:knowledgetechnologyuhh,項目名稱:docks,代碼行數:9,代碼來源:Example.java

示例5: waitForEnter

import java.io.Console; //導入方法依賴的package包/類
public static void waitForEnter() {
    Console c = System.console();
    if (c != null) {

        c.format("\nPress ENTER to proceed.\n");
        c.readLine();
    }
}
 
開發者ID:knowledgetechnologyuhh,項目名稱:docks,代碼行數:9,代碼來源:TestSupervisor.java

示例6: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args){
    Console console = System.console();
    if (console == null) {
        System.err.println("No console.");
        System.exit(1);
    }
    while (true) {
 
        Pattern pattern = 
        Pattern.compile(console.readLine("%nEnter your regex: "));
 
        Matcher matcher = 
        pattern.matcher(console.readLine("Enter input string to search: "));
 
        boolean found = false;
        while (matcher.find()) {
            console.format("I found the text" +
                " \"%s\" starting at " +
                "index %d and ending at index %d.%n",
                matcher.group(),
                matcher.start(),
                matcher.end());
            found = true;
        }
        if(!found){
            console.format("No match found.%n");
        }
    }
}
 
開發者ID:jvilk,項目名稱:doppio-demo,代碼行數:30,代碼來源:RegexTestHarness.java

示例7: main

import java.io.Console; //導入方法依賴的package包/類
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 your 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);
        }
    }
 
開發者ID:low205,項目名稱:JavaTests,代碼行數:31,代碼來源:Password.java

示例8: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) {
    Pattern pattern = null;
    Matcher matcher = null;

    Console console = System.console();
    if (console == null) {
        System.err.println("No console");
        System.exit(1);
    }
    while (true) {
        try {
            pattern = Pattern.compile(console.readLine("%nEnter your regex: "));
            matcher = pattern.matcher(console.readLine("%nEnter input sting to search: "));
        } catch (PatternSyntaxException e) {
            console.format("There is a problem with the regular expression!%n");
            console.format("The description is: %s%n", e.getDescription());
            console.format("The message is: %s%n", e.getMessage());
            console.format("The index is: %s%n", e.getIndex());
            System.exit(0);
        }
        boolean found = false;
        while (matcher.find()) {
            console.format("I found the text" +
                    " \"%s\" starting at " +
                    "index %d and ending at index %d.%n",
                    matcher.group(),
                    matcher.start(),
                    matcher.end());
            found = true;
        }
        if (!found) {
            console.format("No match found.%n");
        }
    }
}
 
開發者ID:low205,項目名稱:JavaTests,代碼行數:36,代碼來源:RegexTestHarness2.java

示例9: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) {
    Console console = System.console();

    if (console == null) {
        System.err.println("No console.");
        System.exit(1);
    }

    while (true) {
        Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: "), Pattern.CASE_INSENSITIVE);

        Matcher matcher = pattern.matcher(console.readLine("Enter input string to search: "));

        boolean found = false;
        while (matcher.find()) {
            console.format("I found the text" +
                    " \"%s\" starting at " +
                    "index % d and ending at index %d.%n",
                    matcher.group(),
                    matcher.start(),
                    matcher.end()
            );
            found = true;
        }
        if (!found) {
            console.format("No match found.%n");
        }
    }
}
 
開發者ID:low205,項目名稱:JavaTests,代碼行數:30,代碼來源:RegexRestHarness.java

示例10: main

import java.io.Console; //導入方法依賴的package包/類
public static void main (String args[]) throws IOException {

        Console c = System.console(); 										// Console object is retrieved
        
        if (c == null) {													// can be null if program is launched in a non-interactive environment
            System.err.println("No console.");
            System.exit(1);
        }

        String login = c.readLine("Enter your login: "); 					// prompt for the username
        char [] oldPassword = c.readPassword("Enter your old password: "); 	// doesn't display characters and returns a char array (not a string) 

        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, ' ');								// Overwrite both passwords with blanks.
                Arrays.fill(newPassword2, ' ');								// Overwrite both passwords with blanks.
            } while (noMatch);
        }

        Arrays.fill(oldPassword, ' ');										// Overwrite both passwords with blanks.
    }
 
開發者ID:bist,項目名稱:learn-core-java,代碼行數:36,代碼來源:StandartStreams.java

示例11: waitForEnter

import java.io.Console; //導入方法依賴的package包/類
private static void waitForEnter() {
	Console c = System.console();
	if (c != null) {
		c.format("\nPress ENTER to proceed.\n");
		c.readLine();
	}
}
 
開發者ID:tobiasschulz,項目名稱:voipcall,代碼行數:8,代碼來源:Main.java

示例12: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String... args){
    Pattern pattern = null;
    Matcher matcher = null;

    Console console = System.console();
    if (console == null) {
        System.err.println("No console.");
        System.exit(1);
    }
    while (true) {
        try {
            pattern = Pattern.compile(console.readLine("%n", "Enter your regex: "));
            matcher =  pattern.matcher(console.readLine("%n", "Enter input string to search: "));
        }
        catch(PatternSyntaxException pse){
            console.format("There is a problem with the regular expression!%n");
            console.format("The pattern in question is: %s%n",pse.getPattern());
            console.format("The description is: %s%n",pse.getDescription());
            console.format("The message is: %s%n",pse.getMessage());
            console.format("The index is: %s%n",pse.getIndex());
            System.exit(0);
        }
        boolean found = false;
        while (matcher.find()) {
            console.format("I found the text \"%s\" starting at " +
               "index %d and ending at index %d.%n",
                matcher.group(), matcher.start(), matcher.end());
            found = true;
        }
        if(!found){
            console.format("No match found.%n");
        }
    }
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:35,代碼來源:RegexTestHarness2.java

示例13: format

import java.io.Console; //導入方法依賴的package包/類
public void format(String message) {
  Console console = System.console();
  console.format(message);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:5,代碼來源:CredentialShell.java

示例14: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String ... p) {
    Formatter f = new Formatter();
    f.format("%d", 1337);
    f.format(Locale.GERMAN, "%d", 1337);
    //:: error: (argument.type.incompatible)
    f.format("%f", 1337);
    //:: error: (argument.type.incompatible)
    f.format(Locale.GERMAN, "%f", 1337);
    f.close();

    String.format("%d", 1337);
    String.format(Locale.GERMAN, "%d", 1337);
    //:: error: (argument.type.incompatible)
    String.format("%f", 1337);
    //:: error: (argument.type.incompatible)
    String.format(Locale.GERMAN, "%f", 1337);

    PrintWriter pw = new PrintWriter(new ByteArrayOutputStream());
    pw.format("%d", 1337);
    pw.format(Locale.GERMAN, "%d", 1337);
    pw.printf("%d", 1337);
    pw.printf(Locale.GERMAN, "%d", 1337);
    //:: error: (argument.type.incompatible)
    pw.format("%f", 1337);
    //:: error: (argument.type.incompatible)
    pw.format(Locale.GERMAN, "%f", 1337);
    //:: error: (argument.type.incompatible)
    pw.printf("%f", 1337);
    //:: error: (argument.type.incompatible)
    pw.printf(Locale.GERMAN, "%f", 1337);
    pw.close();

    PrintStream ps = System.out;
    ps.format("%d", 1337);
    ps.format(Locale.GERMAN, "%d", 1337);
    ps.printf("%d", 1337);
    ps.printf(Locale.GERMAN, "%d", 1337);
    //:: error: (argument.type.incompatible)
    ps.format("%f", 1337);
    //:: error: (argument.type.incompatible)
    ps.format(Locale.GERMAN, "%f", 1337);
    //:: error: (argument.type.incompatible)
    ps.printf("%f", 1337);
    //:: error: (argument.type.incompatible)
    ps.printf(Locale.GERMAN, "%f", 1337);
    ps.close();

    Console c = System.console();
    c.format("%d", 1337);
    c.printf("%d", 1337);
    //:: error: (argument.type.incompatible)
    c.format("%f", 1337);
    //:: error: (argument.type.incompatible)
    c.printf("%f", 1337);
}
 
開發者ID:reprogrammer,項目名稱:checker-framework,代碼行數:56,代碼來源:FormatMethods.java

示例15: main

import java.io.Console; //導入方法依賴的package包/類
/**
 * Sample program to test pattern matching.
 *
 * @param args command line arguments
 * @throws BeliefBaseException thrown if something went wrong
 */
public static void main(String[] args) throws BeliefBaseException {
  BeliefBase bb = new ABeliefStore(100, 4);
  bb.eval(0, "neighbour.age < 31");

  Console console = System.console();
  if (console == null) {
    System.err.println("No console.");
    System.exit(1);
  }
  while (true) {

    Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: "));

    Matcher matcher = pattern.matcher(console.readLine("Enter input string to search: "));

    boolean found = false;
    while (matcher.find()) {
      console.format(
          "I found the text" + " \"%s\" starting at " + "index %d and ending at index %d.%n",
          matcher.group(), matcher.start(), matcher.end());
      found = true;
    }
    if (!found) {
      console.format("No match found.%n");
    }
  }
}
 
開發者ID:agentsoz,項目名稱:jill,代碼行數:34,代碼來源:ABeliefStore.java


注:本文中的java.io.Console.format方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。