List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:ThreadPoolTest.java
public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): "); String directory = in.nextLine(); System.out.print("Enter keyword (e.g. volatile): "); String keyword = in.nextLine(); ExecutorService pool = Executors.newCachedThreadPool(); MatchCounter counter = new MatchCounter(new File(directory), keyword, pool); Future<Integer> result = pool.submit(counter); try {/* w w w . j av a 2 s. c o m*/ System.out.println(result.get() + " matching files."); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { } pool.shutdown(); int largestPoolSize = ((ThreadPoolExecutor) pool).getLargestPoolSize(); System.out.println("largest pool size=" + largestPoolSize); }
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;//w ww . j a v a 2 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:gr.demokritos.iit.demos.Demo.java
public static void main(String[] args) { try {//w ww.j a v a2 s .co m Options options = new Options(); options.addOption("h", HELP, false, "show help."); options.addOption("i", INPUT, true, "The file containing JSON " + " representations of tweets or SAG posts - 1 per line" + " default file looked for is " + DEFAULT_INFILE); options.addOption("o", OUTPUT, true, "Where to write the output " + " default file looked for is " + DEFAULT_OUTFILE); options.addOption("p", PROCESS, true, "Type of processing to do " + " ner for Named Entity Recognition re for Relation Extraction" + " default is NER"); options.addOption("s", SAG, false, "Whether to process as SAG posts" + " default is off - if passed means process as SAG posts"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); // DEFAULTS String filename = DEFAULT_INFILE; String outfilename = DEFAULT_OUTFILE; String process = NER; boolean isSAG = false; if (cmd.hasOption(HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("NER + RE extraction module", options); System.exit(0); } if (cmd.hasOption(INPUT)) { filename = cmd.getOptionValue(INPUT); } if (cmd.hasOption(OUTPUT)) { outfilename = cmd.getOptionValue(OUTPUT); } if (cmd.hasOption(SAG)) { isSAG = true; } if (cmd.hasOption(PROCESS)) { process = cmd.getOptionValue(PROCESS); } System.out.println(); System.out.println("Reading from file: " + filename); System.out.println("Process type: " + process); System.out.println("Processing SAG: " + isSAG); System.out.println("Writing to file: " + outfilename); System.out.println(); List<String> jsoni = new ArrayList(); Scanner in = new Scanner(new FileReader(filename)); while (in.hasNextLine()) { String json = in.nextLine(); jsoni.add(json); } PrintWriter writer = new PrintWriter(outfilename, "UTF-8"); System.out.println("Read " + jsoni.size() + " lines from " + filename); if (process.equalsIgnoreCase(RE)) { System.out.println("Running Relation Extraction"); System.out.println(); String json = API.RE(jsoni, isSAG); System.out.println(json); writer.print(json); } else { System.out.println("Running Named Entity Recognition"); System.out.println(); jsoni = API.NER(jsoni, isSAG); /* for(String json: jsoni){ NamedEntityList nel = NamedEntityList.fromJSON(json); nel.prettyPrint(); } */ for (String json : jsoni) { System.out.println(json); writer.print(json); } } writer.close(); } catch (ParseException | UnsupportedEncodingException | FileNotFoundException ex) { Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.seanmadden.net.fast.SerialInterface.java
public static void main(String[] args) { SerialInterface inter = new SerialInterface(new JSONObject()); inter.open();// w ww . j av a 2 s . c o m System.out.println("Welcome. Commands with 'help'"); String cmd = ""; Scanner scan = new Scanner(System.in); do { System.out.print("> "); cmd = scan.nextLine(); if (cmd.toLowerCase().equals("help")) { System.out.println("Commands:"); System.out.println("help : prints this message"); System.out.println("send <message> : sends <message> to interpretype."); System.out.println("quit : exits this program"); } else if (cmd.toLowerCase().startsWith("send")) { String message = cmd.substring(cmd.toLowerCase().indexOf(' ') + 1); inter.sendDataToPort(message); } } while (!cmd.toLowerCase().equals("quit")); inter.close(); }
From source file:Lab2.java
/** * @param args the command line arguments *//*w w w. jav a2 s . c om*/ public static void main(String[] args) { Preprocessor p = new Preprocessor(); p.parse(); Query q; boolean cont = true; Scanner input = new Scanner(System.in); String yesOrNo; String oOrC; ArrayList<Document> scores; System.out.println("Would you like to use cosine similarity or okapi to score queries? (C/O)"); oOrC = input.nextLine(); while (cont) { System.out.println("Enter a query: "); /** * We don't need the query class, we can just stem it and stopword it then make a document out of it. */ q = new Query(input.nextLine()); if (oOrC.equals("O") || oOrC.equals("o")) { scores = p.calcQueryOkapiScore(q); } else { scores = p.calcQueryCosineSimilarity(q); } System.out.println("Documents returned from cosine similarity analysis on query are: "); for (Document doc : scores) { System.out.println("Text :" + doc.origUtterance); } System.out.println("Would you like to enter another? Y/N"); yesOrNo = input.nextLine(); if (yesOrNo.equals("N") || yesOrNo.equals("n")) { cont = false; } } }
From source file:dingwen.Command.java
public static void main(String[] args) { ShapeCache shapeCache = new ShapeCache(); String filePath = Helper.DEFAULT_FILE; System.out.println(CommonStatement.NOTE); if (args != null && args.length != 0) { filePath = args[0];//from w w w.j a v a 2s . c o m } shapeCache.init(filePath); Scanner scanner = new Scanner(System.in); while (true) { try { String command = scanner.nextLine(); if (command.contains("add")) { Command.addShapeCmd(command, shapeCache); } else if (command.contains("remove")) { Command.removeShapeCmd(command, shapeCache); } else if (command.contains("list")) { Command.listShapesCmd(command, shapeCache); } else if (command.contains("contains")) { Command.containsCmd(command, shapeCache); } else if (command.equals("help shape")) { Command.shapeHelp(); } else if (command.contains("help")) { Command.helpCmd(); } else if (command.contains("exit")) { Command.exitCmd(); break; } else { System.out.println(CommonStatement.INPUT_NOT_RECOGNIZE); } } catch (Exception e) { System.out.println(CommonStatement.INPUT_NOT_RECOGNIZE); } } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0"; Scanner scanner = new Scanner(s); // check if the scanner's next token matches "c" System.out.println(scanner.hasNext("c")); // check if the scanner's next token matches "=" System.out.println(scanner.hasNext("=")); // print the rest of the string System.out.println(scanner.nextLine()); scanner.close();/*from ww w . j a va2 s .c om*/ }
From source file:de.taimos.dvalin.interconnect.model.MessageCryptoUtil.java
/** * start this to generate an AES key or (de/en)crypt data * * @param args the CLI arguments//from w w w . ja v a 2 s . co m */ @SuppressWarnings("resource") public static void main(String[] args) { try { System.out.println("Select (k=generate key; c=crypt; d=decrypt):"); System.out.println(); Scanner scan = new Scanner(System.in, "UTF-8"); if (!scan.hasNextLine()) { return; } switch (scan.nextLine()) { case "k": MessageCryptoUtil.generateKey(); break; case "c": System.out.print("Input data: "); final String data = scan.nextLine(); System.out.println(MessageCryptoUtil.crypt(data)); break; case "d": System.out.print("Input data: "); final String ddata = scan.nextLine(); System.out.println(MessageCryptoUtil.decrypt(ddata)); break; default: break; } } catch (final Exception e) { e.printStackTrace(); } }
From source file:br.upf.contatos.tcp.Client.java
public static void main(String[] args) throws RuntimeException { String teste = Arrays.toString(args); if (args.length == 0) { Client.HOST = "localhost"; } else {//from w w w . jav a 2s. c om Client.HOST = args[0]; } ClientConnector tcpService = new ClientConnector(Client.HOST, PORTA); String line; tcpService.connect(); do { System.out.println("Digite help, para o menu"); Scanner scanner = new Scanner(System.in); line = scanner.nextLine(); } while (comando(line, tcpService)); tcpService.disconnect(); }
From source file:drpc.KMeansDrpcQuery.java
public static void main(final String[] args) throws IOException, TException, DRPCExecutionException, DecoderException, ClassNotFoundException { if (args.length < 3) { System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder"); return;// w ww. ja va2 s.c o m } final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/); final Queue<String> featureFiles = new ArrayDeque<String>(); SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles); Scanner scanner = new Scanner(featureFiles.peek()); int i = 0; while (scanner.hasNextLine() && i++ < 10) { List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine()); for (Map<String, List<Double>> map : dict) { i++; Double[] features = map.get("chi2").toArray(new Double[0]); Double[] moreFeatures = map.get("chi1").toArray(new Double[0]); Double[] rmsd = map.get("rmsd").toArray(new Double[0]); Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures); String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both)); String centroidsSerialized = runQuery(args[1], parameters, client); Gson gson = new Gson(); Object[] deserialized = gson.fromJson(centroidsSerialized, Object[].class); for (Object obj : deserialized) { // result we get is of the form List<result> List l = ((List) obj); centroidsSerialized = (String) l.get(0); String[] centroidSerializedArrays = centroidsSerialized .split(MlStormClustererQuery.KmeansClustererQuery.CENTROID_DELIM); List<double[]> centroids = new ArrayList<double[]>(); for (String centroid : centroidSerializedArrays) { centroids.add(MlStormFeatureVectorUtils.deserializeToFeatureVector(centroid)); } double[] rmsdPrimitive = ArrayUtils.toPrimitive(both); double[] rmsdKmeans = new double[centroids.size()]; for (int k = 0; k < centroids.size(); k++) { System.out.println("centroid -- " + Arrays.toString(centroids.get(k))); double[] centroid = centroids.get(k); rmsdKmeans[k] = computeRootMeanSquare(centroid); } System.out.println("1 rmsd original -- " + Arrays.toString(rmsd)); System.out.println("2 rmsd k- Means -- " + Arrays.toString(rmsdKmeans)); System.out.println(); } } } client.close(); }