List of usage examples for java.util Scanner useDelimiter
public Scanner useDelimiter(String pattern)
From source file:MainClass.java
public static void main(String args[]) throws IOException { Scanner src = new Scanner("1,2,3,4"); src.useDelimiter(", *"); System.out.println(src.delimiter()); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("data.txt"); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); Scanner lineScanner = new Scanner(line); lineScanner.useDelimiter(","); while (lineScanner.hasNext()) { String part = lineScanner.next(); System.out.print(part + ", "); }// ww w .j a v a2 s.c o m System.out.println(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new File("fileName")); scanner.useDelimiter(System.getProperty("line.separator")); while (scanner.hasNext()) { parseLine(scanner.next());// w w w.jav a2 s . co m } scanner.close(); }
From source file:Main.java
public static void main(String args[]) throws IOException { int count = 0; double sum = 0.0; FileWriter fout = new FileWriter("test.txt"); fout.write("2, 3.4, 5,6, 7.4, 9.1, 10.5, done"); fout.close();/*from w w w .jav a 2s . co m*/ FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); src.useDelimiter(", *"); while (src.hasNext()) { if (src.hasNextDouble()) { sum += src.nextDouble(); count++; } else { String str = src.next(); if (str.equals("done")) break; else { System.out.println("File format error."); return; } } } fin.close(); System.out.println("Average is " + sum / count); }
From source file:MainClass.java
public static void main(String args[]) throws IOException { int count = 0; double sum = 0.0; FileWriter fout = new FileWriter("test.txt"); fout.write("2, 3.4, 5,6, 7.4, 9.1, 10.5, done"); fout.close();// w w w .jav a 2s .co m FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); src.useDelimiter(", *"); while (src.hasNext()) { if (src.hasNextDouble()) { sum += src.nextDouble(); count++; } else { String str = src.next(); if (str.equals("done")) break; else { System.out.println("File format error."); return; } } } fin.close(); System.out.println("Average is " + sum / count); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Scanner scanner = new Scanner(s); System.out.println(scanner.nextLine()); // change the delimiter of this scanner scanner.useDelimiter("Wor"); // display the new delimiter System.out.println(scanner.delimiter()); scanner.close();// w ww.ja v a 2 s.co m }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Scanner scanner = new Scanner(s); System.out.println(scanner.nextLine()); // change the delimiter of this scanner scanner.useDelimiter(Pattern.compile(".ll.")); // display the new delimiter System.out.println(scanner.delimiter()); scanner.close();/*from w w w.j a v a2s . c o m*/ }
From source file:com.precioustech.fxtrading.oanda.restapi.marketdata.historic.HistoricMarketDataOnDemandDemo.java
public static void main(String[] args) throws Exception { usage(args);/*from ww w . j a va2 s .c o m*/ final String url = args[0]; final String accessToken = args[1]; HistoricMarketDataProvider<String> historicMarketDataProvider = new OandaHistoricMarketDataProvider(url, accessToken); Scanner scanner = new Scanner(System.in); scanner.useDelimiter(System.getProperty("line.separator")); System.out.print("Instrument" + TradingConstants.COLON); String ccyPair = scanner.next(); TradeableInstrument<String> instrument = new TradeableInstrument<>(ccyPair.toUpperCase()); System.out.print( "Granularity" + ArrayUtils.toString(CandleStickGranularity.values()) + TradingConstants.COLON); CandleStickGranularity granularity = CandleStickGranularity.valueOf(scanner.next().toUpperCase()); System.out.print("Time Range Candles(t) or Last N Candles(n)?:"); String choice = scanner.next(); List<CandleStick<String>> candles = null; if ("t".equalsIgnoreCase(choice)) { System.out.print("Start Time(" + datefmtLabel + ")" + TradingConstants.COLON); String startStr = scanner.next(); Date startDt = sdf.parse(startStr); System.out.print(" End Time(" + datefmtLabel + ")" + TradingConstants.COLON); String endStr = scanner.next(); Date endDt = sdf.parse(endStr); candles = historicMarketDataProvider.getCandleSticks(instrument, granularity, new DateTime(startDt.getTime()), new DateTime(endDt.getTime())); } else { System.out.print("Last how many candles?" + TradingConstants.COLON); int n = scanner.nextInt(); candles = historicMarketDataProvider.getCandleSticks(instrument, granularity, n); } System.out.println(center("Time", timeColLen) + center("Open", priceColLen) + center("Close", priceColLen) + center("High", priceColLen) + center("Low", priceColLen)); System.out.println(repeat("=", timeColLen + priceColLen * 4)); for (CandleStick<String> candle : candles) { System.out.println(center(sdf.format(candle.getEventDate().toDate()), timeColLen) + formatPrice(candle.getOpenPrice()) + formatPrice(candle.getClosePrice()) + formatPrice(candle.getHighPrice()) + formatPrice(candle.getLowPrice())); } scanner.close(); }
From source file:org.trafodion.rest.zookeeper.ZkUtil.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Usage: ZkUtil {command}"); System.exit(1);/* w w w.j av a 2 s . c o m*/ } Options opt = new Options(); CommandLine cmd = null; try { cmd = new GnuParser().parse(opt, args); } catch (NullPointerException e) { System.err.println("No args found: " + e); System.exit(1); } catch (ParseException e) { System.err.println("Could not parse: " + e); System.exit(1); } try { String znode = cmd.getArgList().get(0).toString(); ZkClient zkc = new ZkClient(); zkc.connect(); Stat stat = zkc.exists(znode, false); if (stat == null) { System.out.println(""); } else { List<String> znodes = zkc.getChildren(znode, null); zkc.close(); if (znodes.isEmpty()) { System.out.println(""); } else { Scanner scn = new Scanner(znodes.get(0)); scn.useDelimiter(":"); String hostName = scn.next();//host name scn.close(); System.out.println(hostName); } } } catch (Exception e) { System.err.println(e); e.printStackTrace(); System.exit(1); } }
From source file:com.frederikam.fredboat.bootloader.Bootloader.java
public static void main(String[] args) throws IOException, InterruptedException { OUTER: while (true) { InputStream is = new FileInputStream(new File("./bootloader.json")); Scanner scanner = new Scanner(is); JSONObject json = new JSONObject(scanner.useDelimiter("\\A").next()); scanner.close();/* w ww .j a v a 2s. c o m*/ command = json.getJSONArray("command"); jarName = json.getString("jarName"); Process process = boot(); process.waitFor(); System.out.println("[BOOTLOADER] Bot exited with code " + process.exitValue()); switch (process.exitValue()) { case ExitCodes.EXIT_CODE_UPDATE: System.out.println("[BOOTLOADER] Now updating..."); update(); break; case 130: case ExitCodes.EXIT_CODE_NORMAL: System.out.println("[BOOTLOADER] Now shutting down..."); break OUTER; //SIGINT received or clean exit default: System.out.println("[BOOTLOADER] Now restarting.."); break; } } }