List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:com.rogue.simpleclient.SimpleClient.java
/** * Constructs and authenticates a new client instance. Will ask for input * from a supplied {@link Scanner} source. * * @since 1.0.0/*from w w w . j a va 2s . com*/ * @version 1.0.0 * * @param input The {@link Scanner} to read input from * @throws IOException Any type of communications failure with Mojang */ public SimpleClient(Scanner input) throws IOException { System.out.print("What version are you launching (e.g. '1.7.9')?: "); this.version = input.nextLine(); System.out.print("What is the full path for your application data folder containing minecraft?: "); this.appData = new File(input.nextLine()); this.minecraftDir = new File(this.appData.getAbsoluteFile(), ".minecraft" + File.separatorChar); this.gameDir = new File(minecraftDir, "versions" + File.separator + this.version + File.separatorChar); this.natives = new File(gameDir, "natives" + File.separatorChar); System.out.print("Username: "); String username = input.nextLine(); System.out.print("Password: "); this.connect(username, input.nextLine()); }
From source file:org.apache.uima.ruta.resource.TreeWordList.java
/** * Creates a new Tree in the existing treeWordList from a file with path pathname * // w w w.j a v a 2 s . co m * @param stream * Open InputStream containing the word for the treeWordList, this method will close the * stream. */ public void buildNewTree(InputStream stream) throws IOException { Scanner scan = new Scanner(stream, "UTF-8"); // creating a new tree this.root = new TextNode(); while (scan.hasNextLine()) { String s = scan.nextLine().trim(); // HOTFIX for old formats if (s.endsWith("=")) { s = s.substring(0, s.length() - 1); s = s.trim(); } addWord(s); } scan.close(); }
From source file:FinalProject.Employee_Login.java
private void Submit_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Submit_ButtonActionPerformed String Password = Arrays.toString(Password_Input.getPassword()); String password = Password.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\, ", ""); String username = Employee_Input.getText(); try {//from ww w . j av a2s . co m File user = new File("Username.txt"); File pass = new File("Password.txt"); Scanner scanner = new Scanner(user); FileReader frU = new FileReader(user); LineNumberReader u = new LineNumberReader(frU); FileReader frP = new FileReader(pass); LineNumberReader p = new LineNumberReader(frP); int linenumberU = 0; while (scanner.hasNextLine() && u.readLine() != null) { linenumberU++; String lineFromFile = scanner.nextLine(); if (lineFromFile.contains(username)) // a match! { break; } } String pssLine = (String) FileUtils.readLines(pass).get(linenumberU - 1); String usrLine = (String) FileUtils.readLines(user).get(linenumberU - 1); if (username.equals(usrLine) && password.equals(pssLine)) { this.setVisible(false); Employee_Interface f = new Employee_Interface(); f.setVisible(true); f.ID_Number.setText(usrLine + "!"); } else { Error_Message.setVisible(true); } } catch (FileNotFoundException ex) { } catch (IOException ex) { } }
From source file:edu.ucuenca.authorsrelatedness.Distance.java
public synchronized String Http2(String s, Map<String, String> mp) throws SQLException, IOException { String md = s + mp.toString(); String get = Cache.getInstance().get(md); String resp = ""; if (get != null) { resp = get;//from w w w. ja v a2 s . c o m } else { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(s); method.getParams().setContentCharset("utf-8"); //Add any parameter if u want to send it with Post req. for (Entry<String, String> mcc : mp.entrySet()) { method.addParameter(mcc.getKey(), mcc.getValue()); } int statusCode = client.executeMethod(method); if (statusCode != -1) { InputStream in = method.getResponseBodyAsStream(); final Scanner reader = new Scanner(in, "UTF-8"); while (reader.hasNextLine()) { final String line = reader.nextLine(); resp += line + "\n"; } reader.close(); Cache.getInstance().put(md, resp); } } return resp; }
From source file:Demo.ScatterGraph.java
private void AddDataSet(int x, int y) { List<Integer> failIndexList = new ArrayList<Integer>(); // read fail index Scanner scan = null; try {/* w w w. j a va 2 s.c om*/ scan = new Scanner(new File("data/failIndex.dat")); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this, "failIndex.dat File doesn't exist.", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } while (scan.hasNextLine()) { failIndexList.add(Integer.parseInt(scan.nextLine())); } // read X, Y double[] valueX = Utils.GetParaTab(paraType_list.get(x)); double[] valueY = Utils.GetParaTab(paraType_list.get(y)); // create data set double[][] dataSetPass = new double[2][sampleNb - failIndexList.size()]; double[][] dataSetFail = new double[2][failIndexList.size()]; int i_f = 0; int i_p = 0; for (int i = 0; i < sampleNb; i++) { if (failIndexList.contains(new Integer(i + 1))) { dataSetFail[0][i_f] = valueX[i]; dataSetFail[1][i_f] = valueY[i]; i_f++; } else { dataSetPass[0][i_p] = valueX[i]; dataSetPass[1][i_p] = valueY[i]; i_p++; } } dataSet.addSeries("pass", dataSetPass); dataSet.addSeries("fail", dataSetFail); }
From source file:edu.cmu.cs.lti.ark.fn.parsing.DataPrep.java
private List<List<SpanAndParseIdx>> loadFromCandidateFile(List<String> frameElementLines, InputSupplier<? extends InputStream> candidateInputSupplier) throws IOException { final List<List<SpanAndParseIdx>> candidateLines = Lists.newArrayList(); final Scanner canScanner = new Scanner(candidateInputSupplier.getInput()); for (String ignored : frameElementLines) { final List<SpanAndParseIdx> spanList = Lists.newArrayList(); final String spanTokens[] = canScanner.nextLine().trim().split("\t|:"); for (int i = 0; i < spanTokens.length; i += 2) { final Range0Based span = createSpanRange(parseInt(spanTokens[i]), parseInt(spanTokens[i + 1])); spanList.add(new SpanAndParseIdx(span, 0)); }/* ww w .j a v a2s.c o m*/ //add null span to candidates spanList.add(EMPTY_SPAN_AND_PARSE_IDX); candidateLines.add(spanList); } return candidateLines; }
From source file:ai.grakn.graql.GraqlShell.java
private void printLicense() { StringBuilder result = new StringBuilder(""); //Get file from resources folder ClassLoader classloader = Thread.currentThread().getContextClassLoader(); InputStream is = classloader.getResourceAsStream(LICENSE_LOCATION); Scanner scanner = new Scanner(is, StandardCharsets.UTF_8.name()); while (scanner.hasNextLine()) { String line = scanner.nextLine(); result.append(line).append("\n"); }//from w w w. j a va2s . c o m result.append("\n"); scanner.close(); this.print(result.toString()); }
From source file:de.uzk.hki.da.grid.IrodsCommandLineConnector.java
/** * Gets checksum from ICAT for the newest instance destDao * @author Jens Peters/*from w ww . j ava 2 s . co m*/ * @param destDao * @return */ public String getChecksumOfLatestReplica(String destDao) { String ret = ""; String commandAsArray[] = new String[] { "ils -L", destDao }; String out = executeIcommand(commandAsArray); if (out.indexOf("ERROR") >= 0) throw new RuntimeException(" Get Checksum of " + destDao + " failed !"); Scanner scanner = new Scanner(out); String data_name = FilenameUtils.getName(destDao); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.contains(data_name)) { ret = line.substring(38, line.length()); } } scanner.close(); return ret; }
From source file:edu.ucuenca.authorsrelatedness.Distance.java
public synchronized String Http(String s) throws SQLException, IOException { String get = Cache.getInstance().get(s); String resp = ""; if (get != null) { //System.out.print("."); resp = get;//w w w .ja va 2 s .c o m } else { final URL url = new URL(s); final URLConnection connection = url.openConnection(); connection.setConnectTimeout(60000); connection.setReadTimeout(60000); connection.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0"); connection.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); final Scanner reader = new Scanner(connection.getInputStream(), "UTF-8"); while (reader.hasNextLine()) { final String line = reader.nextLine(); resp += line + "\n"; } reader.close(); Cache.getInstance().put(s, resp); } return resp; }
From source file:com.okta.tools.awscli.java
private static int numSelection(int max) { Scanner scanner = new Scanner(System.in); int selection = -1; while (selection == -1) { //prompt user for selection System.out.print("Selection: "); String selectInput = scanner.nextLine(); try {//w w w .ja v a 2 s . co m selection = Integer.parseInt(selectInput) - 1; if (selection >= max) { InputMismatchException e = new InputMismatchException(); throw e; } } catch (InputMismatchException e) { //raised by something other than a number entered logger.error("Invalid input: Please enter a number corresponding to a role \n"); selection = -1; } catch (NumberFormatException e) { //raised by number too high or low selected logger.error("Invalid input: Please enter in a number \n"); selection = -1; } } return selection; }