List of usage examples for java.util Scanner Scanner
public Scanner(ReadableByteChannel source)
From source file:com.aduyko.nearby.NearbyPlaces.java
public static String getInputIp() { System.out.println("Please specify an Ip address to find nearby places:"); Scanner scanner = new Scanner(System.in); String inputIp = scanner.nextLine(); return inputIp; }
From source file:br.upf.contatos.udp.ClienteUDP.java
public static boolean comando(String[] args) throws SocketException, IOException { while (true) { Scanner scanner = new Scanner(System.in); String line = scanner.nextLine(); String[] comandos = line.split(" "); if (comandos[0].equals("help")) { System.out.println("Listar = Lista todos os contatos" + "incluir = Inclui um contato, incluir nome NOMEtudoJUNTO email EMAIL end ENDERECO comp COPM cep CEP cid CID est EST \n" + "editar = edita um contato, escrever editar numeroDoID label VALORaSERalterado\n" + "deletar = deletar id numero \n" + "parar = finaliza conexao \n" + "cidade = lista por cidade escrever cidade nomeCidade\n" + "Comandos seguidos de outras informacoes sempre separar por espaco, nomes tudo junto\n"); return true; } else if (comandos[0].equals("parar")) { return false; } else {/*from w ww. java 2 s . c o m*/ UDPConexao udpConnection = new UDPConexao(HOST, PORTA); udpConnection.connect(); switch (comandos[0]) { case "listar": { for (ContatoBean cb : udpConnection.getAll()) { System.out.println(new JSONObject(cb)); } udpConnection.disconnect(); break; } // TERMINA LISTAR case "incluir": { ContatoBean cb = new ContatoBean(); if (comandos[1].equals("label=nome")) cb.setNome(comandos[2]); if (comandos[3].equals("label=email")) cb.setEmail(comandos[4]); if (comandos[5].equals("label=end")) cb.setEndereco(comandos[6]); if (comandos[7].equals("label=comp")) cb.setComplemento(comandos[8]); if (comandos[9].equals("label=cep")) cb.setCep(Integer.parseInt(comandos[10])); if (comandos[11].equals("label=cid")) cb.setCidade(comandos[12]); if (comandos[13].equals("label=est")) cb.setEstado(comandos[14]); try { cb = udpConnection.insert(cb); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); break; } //TERMINA INCLUIR case "editar": { int numIdEdi = Integer.parseInt(args[1]); ContatoBean contact = new ContatoBean(); contact = udpConnection.getById(numIdEdi); switch (args[2]) { case "id": contact.setId(Integer.parseInt(args[3])); break; case "nome": contact.setNome(args[3]); break; case "email": contact.setEmail(args[3]); break; case "end": contact.setEndereco(args[3]); break; case "comp": contact.setComplemento(args[3]); break; case "cep": contact.setCep(Integer.parseInt(args[3])); break; case "cid": contact.setCidade(args[3]); break; case "est": contact.setEstado(args[3]); break; }// FINALIZA CASE DE TROCA DE DADOS try { contact = udpConnection.update(contact); System.out.println(new JSONObject(contact)); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); } // TERMINA EDITAR case "cidade": { ContatoBean cob = new ContatoBean(); cob.setCidade(args[1]); try { cob = udpConnection.getByCidade(cob); System.out.println(new JSONObject(cob)); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); break; } //termina listar CIDADE case "deletar": { ContatoBean cb = new ContatoBean(); cb.setId(Integer.parseInt(args[1])); try { cb = udpConnection.delete(cb.getId()); System.out.println(new JSONObject(cb)); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); break; } //termina DELETAR }//TERMINA SWTICH } // TERMINA ELSE ANTES DO SWITCH } //TERMINA WILHER TRUE }
From source file:com.project.atm.core.App.java
static void loadLocationdata() throws FileNotFoundException { /*//from w w w . j av a2 s. co m The location will load 2 files : 1. LocationCode files This file content is for location list 2. Distance matrix files This file content is for list of distance for every location */ //change the path file to correct location ! scLoc = new Scanner(new FileReader("/home/andry/Documents/atm/LocationCode.txt")); boolean firstFlag = false; logger.info("loading location code from tab file......................."); while (scLoc.hasNextLine()) { // skip the header if (!firstFlag) { scLoc.nextLine(); firstFlag = true; } String[] locArr = scLoc.nextLine().split("\t"); locationList.add(new Location(Integer.valueOf(locArr[0]), locArr[1])); } //System.out.println("location list => "+locationList.toString()); }
From source file:OpenCalaisGenerateRdfPropertiesFromWebPages.java
public OpenCalaisGenerateRdfPropertiesFromWebPages(String config_file_path, PrintWriter out) throws IOException { this.out = out; List<String> lines = (List<String>) FileUtils.readLines(new File(config_file_path)); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); try {//from w w w .j a v a 2s . co m String starting_url = scanner.next(); int spider_depth = Integer.parseInt(scanner.next()); spider(starting_url, spider_depth); } catch (Exception ex) { ex.printStackTrace(); } } this.out.close(); }
From source file:net.ftb.util.AppUtils.java
/** * Reads all of the data from the given stream and returns it as a string. * @param stream the stream to read from. * @return the data read from the given stream as a string. *///from w ww . j ava 2 s.c om public static String readString(InputStream stream) { Scanner scanner = new Scanner(stream).useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; }
From source file:azureml_besapp.AzureML_BESApp.java
/** * Read the API key and API URL of Azure ML request response REST API * //from ww w . j a va 2s .c o m * @param filename fully qualified file name that contains API key and API URL */ public static void readApiInfo(String filename) { try { File apiFile = new File(filename); Scanner sc = new Scanner(apiFile); apiurl = sc.nextLine(); apikey = sc.nextLine(); startJobUrl = sc.nextLine(); } catch (Exception e) { System.out.println(e.toString()); } }
From source file:Main.java
public static MatchResult matchSystemFile(final String pSystemFile, final String pPattern, final int pHorizon) throws Exception { InputStream in = null;//from w ww . j a v a 2 s . co m try { final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start(); in = process.getInputStream(); final Scanner scanner = new Scanner(in); final boolean matchFound = scanner.findWithinHorizon(pPattern, pHorizon) != null; if (matchFound) { return scanner.match(); } else { throw new Exception(); } } catch (final IOException e) { throw new Exception(e); } }
From source file:com.mirth.connect.server.util.DatabaseUtil.java
public static void executeScript(String script, boolean ignoreErrors) throws Exception { SqlSessionManager sqlSessionManger = SqlConfig.getSqlSessionManager(); Connection conn = null;// ww w . j av a2s . c o m ResultSet resultSet = null; Statement statement = null; try { sqlSessionManger.startManagedSession(); conn = sqlSessionManger.getConnection(); /* * Set auto commit to false or an exception will be thrown when trying to rollback */ conn.setAutoCommit(false); statement = conn.createStatement(); Scanner s = new Scanner(script); while (s.hasNextLine()) { StringBuilder sb = new StringBuilder(); boolean blankLine = false; while (s.hasNextLine() && !blankLine) { String temp = s.nextLine(); if (temp.trim().length() > 0) sb.append(temp + " "); else blankLine = true; } // Trim ending semicolons so Oracle doesn't throw // "java.sql.SQLException: ORA-00911: invalid character" String statementString = StringUtils.removeEnd(sb.toString().trim(), ";"); if (statementString.length() > 0) { try { statement.execute(statementString); conn.commit(); } catch (SQLException se) { if (!ignoreErrors) { throw se; } else { logger.error("Error was encountered and ignored while executing statement: " + statementString, se); conn.rollback(); } } } } } catch (Exception e) { throw new Exception(e); } finally { DbUtils.closeQuietly(statement); DbUtils.closeQuietly(resultSet); DbUtils.closeQuietly(conn); sqlSessionManger.close(); } }
From source file:Main.java
/** * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as built from the * URI's query portion. For example, a URI of * http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three * NameValuePairs, one for a=1, one for b=2, and one for c=3. * <p/>/* ww w .j av a 2s.c o m*/ * This is typically useful while parsing an HTTP PUT. * * @param uri uri to parse */ public static List<NameValuePair> parse(final URI uri) { final String query = uri.getRawQuery(); if (!TextUtils.isEmpty(query)) { List<NameValuePair> result = new ArrayList<NameValuePair>(); Scanner scanner = new Scanner(query); parse(result, scanner); return result; } else { return Collections.emptyList(); } }
From source file:Matrix_Operations.java
public static int getColumnNumberFromUser() { Scanner keyboard = new Scanner(System.in); //Allow user to enter number of columns int columns;// ww w . ja va2s. c om System.out.print("Enter columns: "); columns = keyboard.nextInt(); return columns; }