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


Java Console.readLine方法代碼示例

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


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

示例1: process

import java.io.Console; //導入方法依賴的package包/類
/**
 * Run through the Smart Content APIs and show usage
 */
public void process() {
    SmartContentApi client = new SmartContentClient().getClient();
    String input;

    Console cmdline = System.console();
    if (cmdline == null) {
        System.err.println("No console for command line demo.");
        System.exit(1);
    }

    // Find a Smart Data concept
    input = cmdline.readLine("Enter text to find concepts, categories or entities: ");

    System.out.println(findSmartContentDemo(client, input).toString());
}
 
開發者ID:DataNinjaAPI,項目名稱:dataninja-smartcontent-api-sdk-java,代碼行數:19,代碼來源:SmartContentDemo.java

示例2: doConsole

import java.io.Console; //導入方法依賴的package包/類
private void doConsole() throws Exception
{
    Console console = System.console();

    if (console != null) // IDE not support
    {
        String className = console.readLine("> ");

        CommandManager commandManager = new CommandManager();

        while (commandManager.execute(new CommandFactory().createCommand(className)))
        {
            console.printf(NEW_LINE);

            className = console.readLine("> ");
        }
    }
}
 
開發者ID:geekflow,項目名稱:light,代碼行數:19,代碼來源:Main.java

示例3: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) {
	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!");
	}
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:12,代碼來源:ConsoleDemo.java

示例4: mongodbInstall

import java.io.Console; //導入方法依賴的package包/類
private MongoDBConfig mongodbInstall() {
	MongoDBConfig mongoDBConfig;
	String ip;
	String port;

	do {
		Console console = System.console();
		log.info("Please enter the ip for MongoDB");
		ip = console.readLine();

		log.info("Please enter the port");
		port = console.readLine();

		mongoDBConfig = new MongoDBConfig();
		mongoDBConfig.setIp(ip);
		mongoDBConfig.setPort(port);
		log.info("Please wait");
	} while (!MongoDBConnectionTest.connectionTest(mongoDBConfig));
	return mongoDBConfig;
}
 
開發者ID:MinecraftCloudSystem,項目名稱:MCS-Master,代碼行數:21,代碼來源:DatabaseInstallation.java

示例5: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    String path = System.getenv("LR");
    if (path == null || path.isEmpty()) {
        throw new RuntimeException("Bad value in environment variable");
    }

    File file = new File(path);
    file.getParentFile().mkdirs();
    Console console = System.console();

    // read username and password
    String user = console.readLine("Username: ");
    char[] passwd = console.readPassword("Password: ");

    // experiment with UserEndpoints.CredentialProvider
    MyCredentials credentials = new MyCredentials(user, passwd);
    RestUserEndpoints endpoints = new RestUserEndpoints();
    // add HttpLoggingInterceptor, log as much ask possible
    endpoints.addInterceptor(new HttpLoggingInterceptor(new MyLogger()).setLevel(HttpLoggingInterceptor.Level.BODY));
    endpoints.setupEndpoints();
    LoginResponse loginResponse = endpoints.doLogin(credentials);
    // this should be done to minimize password leakage but other parts of library must be changed to support char arrays
    Arrays.fill(passwd, '0');

    // finally save LoginResponse to disk
    String login = JsonFactory.GSON.toJson(loginResponse);
    PrintWriter writer = new PrintWriter(file);
    writer.print(login);
    writer.close();

    // just close JVM. Otherwise it will wait okio daemon timeouts
    System.exit(0);
}
 
開發者ID:progwml6,項目名稱:JavaCurseAPI,代碼行數:34,代碼來源:AuthTokenGenerator.java

示例6: promptForConfirmation

import java.io.Console; //導入方法依賴的package包/類
public static boolean promptForConfirmation(String prompt) {
  Console console = System.console();
  if (System.console() != null) {
    Boolean confirm = null;
    while (confirm == null) {
      String response = console.readLine(prompt + " (y/n) ");
      if (response.toLowerCase().startsWith("y")) {
        confirm = true;
      } else if (response.toLowerCase().startsWith("n")) {
        confirm = false;
      }
    }
    return confirm.booleanValue();
  } else {
    System.out.println(prompt + "\n");
    System.out.println("Unable to get a response because you are " +
                       "redirecting input.\nI'm just gonna assume the " +
                       "answer is no.\n\n" +
                       "To auto-respond yes, use the -y/--yes option.");
    return false;
  }
}
 
開發者ID:alda-lang,項目名稱:alda-client-java,代碼行數:23,代碼來源:Util.java

示例7: 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

示例8: getConsoleInstance

import java.io.Console; //導入方法依賴的package包/類
/**
 * Creates an instance that prompts the console user to enter data after prompts.
 * @prompt A String prompt to be displayed for the user on the console.
 * @noEcho A boolean indicating if the user-entered text should be hidden from the console; usually for passwords.
 */
public static final UserInterface getConsoleInstance()
{
	return new UserInterface()
	{
		@Override public String getUserInput(String prompt, boolean noEcho, TAC_PLUS.AUTHEN.STATUS getWhat)
		{
			Console console = System.console();
			if (console == null) { System.out.println("No console available!"); return null; }
			System.out.println();
			System.out.print(prompt);
			String input = noEcho? new String(console.readPassword()) : console.readLine();
			if (getWhat == TAC_PLUS.AUTHEN.STATUS.GETUSER) { this.username = input; }
			return input;
		}
	};
}
 
開發者ID:AugurSystems,項目名稱:TACACS,代碼行數:22,代碼來源:UserInterface.java

示例9: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) {
    String databaseFile = "";
    if (args.length >= 1) {
        databaseFile = args[0];
    }

    DataSource dataSource = getDataSourceFrom(databaseFile);
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    resultSetExtractor = new StringResultSetExtractor();
    queryExecutor = new QueryExecutor(jdbcTemplate);

    Console console = getConsole();

    String command;
    while (true) {
        System.out.print("$>");
        command = console.readLine();
        if (command.equalsIgnoreCase("quit")) {
            break;
        }
        process(command);
    }
    System.out.println("bye!");
}
 
開發者ID:benas,項目名稱:jql,代碼行數:25,代碼來源:Shell.java

示例10: main

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

       logger.info("Entering application.");
       
	Console console = System.console();
       if (console == null) {
           logger.error("No console.");
           System.exit(1);
       }
       
       String name = console.readLine("Please enter your name: ");
       String emailAddress = console.readLine("Please enter your email address: ");
       
       logger.info(String.format("User %s entered email address: %s", name, emailAddress));

       UserService userService = context.getBean(UserService.class);
	userService.createUser(name, emailAddress);		
	
       logger.info("Exiting application.");
}
 
開發者ID:cnasenberg,項目名稱:sparrow,代碼行數:22,代碼來源:Application.java

示例11: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create CXF REST service and inject the dummy backend
    RestOrderService rest = new RestOrderService();
    rest.setOrderService(dummy);

    // setup Apache CXF REST server on port 9000
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(RestOrderService.class);
    sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest));
    sf.setAddress("http://localhost:9000/");

    // create and start the CXF server (non blocking)
    Server server = sf.create();
    server.start();

    // keep the JVM running
    Console console = System.console();
    System.out.println("Server started on http://localhost:9000/");
    System.out.println("");

    // If you run the main class from IDEA/Eclipse then you may not have a console, which is null)
    if (console != null) {
        System.out.println("  Press ENTER to stop server");
        console.readLine();
    } else {
        System.out.println("  Stopping after 5 minutes or press ctrl + C to stop");
        Thread.sleep(5 * 60 * 1000);
    }

    // stop CXF server
    server.stop();
    System.exit(0);
}
 
開發者ID:camelinaction,項目名稱:camelinaction2,代碼行數:38,代碼來源:RestOrderServer.java

示例12: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  NewsmthRobot robot = new NewsmthRobot();
  String username;
  String password;
  File passwd = new File("passwd.newsmth");
  if (passwd.exists() && passwd.isFile()) {
    System.out.println("passwd file detected, using it...");
    BufferedReader reader = new BufferedReader(new InputStreamReader(
        new FileInputStream(passwd), "UTF-8"));
    username = reader.readLine();
    password = reader.readLine();
    reader.close();
  } else {
    System.out
        .println("No passwd file found. Type your username and hit enter:");
    Console console = System.console();
    username = console.readLine();
    System.out.println("Type your password and hit enter:");
    password = new String(console.readPassword());
  }
  System.out.println("Logging in...");
  robot.login(username, password);
  for (File f : new File(".").listFiles()) {
    if (f.isFile() && f.getName().startsWith("newsmth")) {
      System.out.println("Posting " + f.getName() + "...");
      Thread.sleep(10000);
      String[] data = robot.readPostData(f);
      robot.post(data[0], data[1], data[2]);
    }
  }
  System.out.println("Done...");
}
 
開發者ID:cameoh,項目名稱:forum-bot,代碼行數:33,代碼來源:NewsmthRobot.java

示例13: main

import java.io.Console; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  ByrRobot robot = new ByrRobot();
  String username = null;
  String password = null;
  File passwd = new File("passwd.byr");
  if (passwd.exists() && passwd.isFile()) {
    System.out.println("passwd file detected, using it...");
    BufferedReader reader = new BufferedReader(new InputStreamReader(
        new FileInputStream(passwd), "UTF-8"));
    username = reader.readLine();
    password = reader.readLine();
    reader.close();
  } else {
    System.out
        .println("No passwd file found. Type your username and hit enter:");
    Console console = System.console();
    username = console.readLine();
    System.out.println("Type your password and hit enter:");
    password = new String(console.readPassword());
  }
  System.out.println("Logging in...");
  robot.login(username, password);
  for (File f : new File(".").listFiles()) {
    if (f.isFile() && f.getName().startsWith("byr")) {
      System.out.println("Posting " + f.getName() + "...");
      Thread.sleep(6000);
      String[] data = robot.readPostData(f);
      System.out.println(robot.post(data[0], data[1], data[2]));
    }
  }
  System.out.println("Done...");
}
 
開發者ID:cameoh,項目名稱:forum-bot,代碼行數:33,代碼來源:ByrRobot.java

示例14: getBasicAuthenticationInput

import java.io.Console; //導入方法依賴的package包/類
public static String[] getBasicAuthenticationInput() {
    String username = null;
    String password = null;

    try {
        Console console = System.console();
        username = console.readLine("Enter username for atlas :- ");

        char[] pwdChar = console.readPassword("Enter password for atlas :- ");
        if(pwdChar != null) {
            password = new String(pwdChar);
        }

    } catch (Exception e) {
        System.out.print("Error while reading ");
        System.exit(1);
    }
    return new String[]{username, password};
}
 
開發者ID:apache,項目名稱:incubator-atlas,代碼行數:20,代碼來源:AuthenticationUtil.java

示例15: getUsername

import java.io.Console; //導入方法依賴的package包/類
private String getUsername() {
	Console cons;
	String username = null;
	if ((cons = System.console()) != null) {
		while (username == null) {
			username = cons.readLine("%s", "Login :");
			if (username == null || username.equals("")) {
				continue;
			}
		}
	}
	return username;
}
 
開發者ID:sylvainleroux,項目名稱:bank,代碼行數:14,代碼來源:UpdatePassword.java


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