List of usage examples for java.util Scanner Scanner
public Scanner(ReadableByteChannel source)
From source file:ReflectionTest.java
public static void main(String[] args) { // read class name from command line args or user input String name;/*from www . j a va 2s .c om*/ if (args.length > 0) name = args[0]; else { Scanner in = new Scanner(System.in); System.out.println("Enter class name (e.g. java.util.Date): "); name = in.next(); } try { // print class name and superclass name (if != Object) Class cl = Class.forName(name); Class supercl = cl.getSuperclass(); String modifiers = Modifier.toString(cl.getModifiers()); if (modifiers.length() > 0) System.out.print(modifiers + " "); System.out.print("class " + name); if (supercl != null && supercl != Object.class) System.out.print(" extends " + supercl.getName()); System.out.print("\n{\n"); printConstructors(cl); System.out.println(); printMethods(cl); System.out.println(); printFields(cl); System.out.println("}"); } catch (ClassNotFoundException e) { e.printStackTrace(); } System.exit(0); }
From source file:id3Crawler.java
public static void main(String[] args) throws IOException { //Input for the directory to be searched. System.out.println("Please enter a directory: "); Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); //Start a timer to calculate runtime startTime = System.currentTimeMillis(); System.out.println("Starting scan..."); //Files for output PrintWriter pw1 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Song.txt")); PrintWriter pw2 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Artist.txt")); PrintWriter pw3 = new PrintWriter(new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/Album.txt")); PrintWriter pw4 = new PrintWriter( new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/PerformedBy.txt")); PrintWriter pw5 = new PrintWriter( new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/TrackOf.txt")); PrintWriter pw6 = new PrintWriter( new FileWriter("C:/Users/gbob3_000/Desktop/id3CrawlerOutput/CreatedBy.txt")); //This is used for creating IDs for artists, songs, albums. int idCounter = 0; //This is used to prevent duplicate artists String previousArtist = " "; String currentArtist;/*from ww w . j av a2 s . c o m*/ int artistID = 0; //This is used to prevent duplicate albums String previousAlbum = " "; String currentAlbum; int albumID = 0; //This array holds valid extensions to iterate through String[] extensions = new String[] { "mp3" }; //iterate through all files in a directory Iterator<File> it = FileUtils.iterateFiles(new File(input), extensions, true); while (it.hasNext()) { //open the next file File file = it.next(); //instantiate an mp3file object with the opened file MP3 song = GetMP3(file); //pass the song through SongInfo and return the required information SongInfo info = new SongInfo(song); //This is used to prevent duplicate artists/albums currentArtist = info.getArtistInfo(); currentAlbum = info.getAlbumInfo(); //Append the song information to the end of a text file pw1.println(idCounter + "\t" + info.getTitleInfo()); //This prevents duplicates of artists if (!(currentArtist.equals(previousArtist))) { pw2.println(idCounter + "\t" + info.getArtistInfo()); previousArtist = currentArtist; artistID = idCounter; } //This prevents duplicates of albums if (!(currentAlbum.equals(previousAlbum))) { pw3.println(idCounter + "\t" + info.getAlbumInfo()); previousAlbum = currentAlbum; albumID = idCounter; //This formats the IDs for a "CreatedBy" relationship table pw6.println(artistID + "\t" + albumID); } //This formats the IDs for a "PerformedBy" relationship table pw4.println(idCounter + "\t" + artistID); //This formats the IDs for a "TrackOf" relationship table pw5.println(idCounter + "\t" + albumID); idCounter++; songCounter++; } scanner.close(); pw1.close(); pw2.close(); pw3.close(); pw4.close(); pw5.close(); pw6.close(); System.out.println("Scan took " + ((System.currentTimeMillis() - startTime) / 1000.0) + " seconds to scan " + songCounter + " items!"); }
From source file:com.grayfox.server.Program.java
public static void main(String[] args) { try (AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( MainConfig.class)) { new Program().run(applicationContext, new Scanner(System.in)); } catch (Exception ex) { LOGGER.error("Error during execution", ex); }//from www . j a v a 2s . com }
From source file:com.richard.memorystore.udp.UDPServer.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*w w w .j a va2s. c om*/ */ public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration " + "\n TCP-Client-Server Sample! " + "\n " + "\n For more information please visit: " + "\n http://www.springintegration.org/ " + "\n " + "\n========================================================="); final GenericXmlApplicationContext context = UDPServer.setupContext(); // final SimpleGateway gateway = context.getBean(SimpleGateway.class); // final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class); System.out.print("Waiting for server to accept connections..."); //TestingUtilities.waitListening(crLfServer, 10000L); System.out.println("running.\n\n"); System.out.println("Please enter some text and press <enter>: "); System.out.println("\tNote:"); System.out.println("\t- Entering FAIL will create an exception"); System.out.println("\t- Entering q will quit the application"); System.out.print("\n"); System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests."); //System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n"); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } // else { // final String result = gateway.send(input); // System.out.println(result); // } } System.out.println("Exiting application...bye."); System.exit(0); }
From source file:org.bitcoinrt.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments// w w w . j av a 2 s .c o m */ public static void main(final String... args) { final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration Bitcoin-rt Sample! " + "\n " + "\n========================================================="); System.out.println("Which WebSocket Client would you like to use? <enter>: "); System.out.println("\t1. Use Sonatype's Async HTTP Client implementation"); System.out.println("\t2. Use Jetty's WebSocket client implementation"); System.out.println("\t3. Use a Dummy client"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { context.getEnvironment().setActiveProfiles("default"); break; } else if ("2".equals(input.trim())) { context.getEnvironment().setActiveProfiles("jetty"); break; } else if ("3".equals(input.trim())) { context.getEnvironment().setActiveProfiles("dummy"); break; } else if ("q".equals(input.trim())) { System.out.println("Exiting application...bye."); System.exit(0); } else { System.out.println("Invalid choice\n\n"); System.out.print("Enter you choice: "); } } context.load("classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); context.refresh(); final ConnectionBroker connectionBroker = context.getBean(ConnectionBroker.class); if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n For statistical information press 'i + Enter'. " + "\n " + "\n In your browser open: " + "\n file:///.../src/main/webapp/index.html " + "\n========================================================="); } while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } else if ("i".equals(input.trim())) { LOGGER.info("\n=========================================================" + "\n " + "\n Number of connected clients: " + connectionBroker.connectedClients() + "\n " + "\n========================================================="); } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Exiting application...bye."); } context.close(); System.exit(0); }
From source file:com.hsbc.srbp.commonMsg.test.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//w ww.j a v a 2 s.c om */ public static void main(final String... args) { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "jdbcInboundApplicationContext.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final CommonMessageService commonMessageService = context.getBean(CommonMessageService.class); System.out.println("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Create a new message detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { createMessageDetails(scanner, commonMessageService, context); } else if ("q".equals(input.trim())) { break; } else { System.out.println("Invalid choice\n\n"); } System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Create a new message detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); } System.out.println("Exiting application...."); System.exit(0); }
From source file:GenericReflectionTest.java
public static void main(String[] args) { // read class name from command line args or user input String name;//from w w w .j av a 2 s . c o m if (args.length > 0) name = args[0]; else { Scanner in = new Scanner(System.in); System.out.println("Enter class name (e.g. java.util.Collections): "); name = in.next(); } try { // print generic info for class and public methods Class<?> cl = Class.forName(name); printClass(cl); for (Method m : cl.getDeclaredMethods()) printMethod(m); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:com.envirover.spl.SPLGroundControl.java
public static void main(String[] args) { try {//from ww w . java2 s . co m SPLDaemon daemon = new SPLDaemon(); daemon.init(new SPLDaemonContext(args)); daemon.start(); System.out.println("Enter 'stop' to exit the program."); Scanner scanner = new Scanner(System.in); String str; while (!(str = scanner.next()).equalsIgnoreCase("stop")) { //Just echo the user input for now. System.out.println(str); } System.out.println("Exiting..."); scanner.close(); daemon.stop(); daemon.destroy(); System.out.println("Done."); System.exit(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } }
From source file:cit360.sandbox.CIT360SandBox.java
public static void main(String[] args) throws Exception { Scanner input = new Scanner(System.in); System.out.println("What is your name?"); CIT360SandBox.firstName = input.next(); System.out.println("Welcome " + firstName + "!"); CIT360SandBox.App.mainMenu();//from www .j av a2s . co m }
From source file:bankconsoleapp.console.Main.java
/** * @param args the command line arguments */// w w w . j a v a 2 s. c o m public static void main(String[] args) { //Injecting applicationContext to main ApplicationContext context = new ClassPathXmlApplicationContext("bankconsoleapp/applicationContext.xml"); EmployeeService eS = context.getBean("EmployeeService", EmployeeService.class); CustomerService cS = context.getBean("CustomerService", CustomerService.class); SavingService sS = context.getBean("SavingService", SavingService.class); String userName, pass; Scanner in = new Scanner(System.in); boolean user = false; boolean savingRedo = false; do { System.out.println("Enter Employee ID:"); userName = in.nextLine(); for (Employee emp : eS.getAllEmp()) { if (userName.equals(emp.geteID())) { System.out.println("Password:"); pass = in.nextLine(); for (Employee em : eS.getAllEmp()) { if (pass.equals(em.getPassword())) { user = true; } } } } } while (!user); long start = System.currentTimeMillis(); long end = start + 60 * 1000; // 60 seconds * 1000 ms/sec int operation = 0; int userChoice; boolean quit = false; do { System.out.println("ACME Bank Saving System:"); System.out.println("------------------------"); System.out.println("1. Create Customer & Saving Account"); System.out.println("2. Deposit Money"); System.out.println("3. Withdraw Money"); System.out.println("4. View Balance"); System.out.println("5. Quit"); System.out.print("Operation count: " + operation + "(Shut down at 5)"); userChoice = in.nextInt(); switch (userChoice) { case 1: //create customer, then saving account regard to existing customer( maximum 2 SA per Customer) System.out.println("Create Customer :"); String FirstN, LastN, DoB, accNum, answer; Scanner sc = new Scanner(System.in); Customer c = new Customer(); int saID = 0; System.out.println("Enter First Name:"); FirstN = sc.nextLine(); c.setFname(FirstN); System.out.println("Enter Last Name:"); LastN = sc.nextLine(); c.setLname(LastN); System.out.println("Enter Date of Birth:"); DoB = sc.nextLine(); c.setDoB(DoB); do { System.out.println("Creating saving acount, Enter Account Number:"); accNum = sc.nextLine(); c.setSA(accNum); c.setSavingAccounts(c.getSA()); saID++; System.out.println("Create another SA? Y/N?"); answer = sc.nextLine(); if (answer.equals("n")) { savingRedo = true; } if (saID == 2) { System.out.println("Maximum Saving account reached!"); } } while (!savingRedo && saID != 2); cS.createCustomer(c); operation++; break; case 2: // deposit String acNum; int amt; Scanner sc1 = new Scanner(System.in); System.out.println("Enter Saving Account number u wish to do deposit."); acNum = sc1.nextLine(); System.out.println("Enter amount :"); amt = sc1.nextInt(); sS.deposit(acNum, amt); operation++; break; case 3: String acNums; int amts; Scanner sc2 = new Scanner(System.in); System.out.println("Enter Saving Account number u wish to do withdraw."); acNums = sc2.nextLine(); System.out.println("Enter amount :"); amts = sc2.nextInt(); sS.withdraw(acNums, amts); operation++; break; case 4: // view System.out.println("Saving Account Balance:"); System.out.println(sS.getAllSA()); operation++; break; case 5: quit = true; break; default: System.out.println("Wrong choice."); break; } System.out.println(); if (operation == 5) { System.out.println("5 operation reached, System shutdown."); } if (System.currentTimeMillis() > end) { System.out.println("Session Expired."); } } while (!quit && operation != 5 && System.currentTimeMillis() < end); System.out.println("Bye!"); }