List of usage examples for java.util Scanner close
public void close()
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true 9000000000000000000000L"; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { System.out.println("Not Found :" + scanner.next()); if (scanner.hasNextLong()) { System.out.println("Found :" + scanner.nextLong(20)); }//from ww w . j a va 2s . c om } scanner.close(); }
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); while (scanner.hasNext()) { if (scanner.hasNextInt()) { System.out.println("Found :" + scanner.nextInt()); }/*w w w. j a va 2 s. co m*/ System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
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 next token is "java" System.out.println(scanner.hasNext("java")); // find the last match and print it System.out.println(scanner.match()); System.out.println(scanner.nextLine()); scanner.close(); }
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); while (scanner.hasNext()) { if (scanner.hasNextShort()) { System.out.println("Found :" + scanner.nextShort(4)); }/* w ww .j a va2 s . c o m*/ System.out.println("Not Found :" + scanner.next()); } scanner.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Long l = 123456789098765432L; s = s + l;// w ww .ja v a2 s . c o m Scanner scanner = new Scanner(s); while (scanner.hasNext()) { System.out.println("Not Found :" + scanner.next()); if (scanner.hasNextLong()) { System.out.println("Found :" + scanner.nextLong()); } } scanner.close(); }
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 source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Float f = 1.2385f;//from ww w . j av a 2 s.c o m s = s + f; Scanner scanner = new Scanner(s); scanner.useLocale(Locale.US); while (scanner.hasNext()) { scanner.next(); if (scanner.hasNextFloat()) { System.out.println("Found :" + scanner.nextFloat()); } } scanner.close(); }
From source file:Main.java
public static void main(String[] args) throws FileNotFoundException { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt").getChannel()); System.out.println(scanner.nextLine()); // change the radix of the scanner scanner.useRadix(32);//from w w w .j a v a2 s. c om // display the new radix System.out.println(scanner.radix()); scanner.close(); }
From source file:LogTest.java
public static void main(String[] args) throws IOException { String inputfile = args[0];//from ww w .j a v a2 s . co m String outputfile = args[1]; Map<String, Integer> map = new TreeMap<String, Integer>(); Scanner scanner = new Scanner(new File(inputfile)); while (scanner.hasNext()) { String word = scanner.next(); Integer count = map.get(word); count = (count == null ? 1 : count + 1); map.put(word, count); } scanner.close(); List<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); PrintWriter out = new PrintWriter(new FileWriter(outputfile)); for (String key : keys) out.println(key + " : " + map.get(key)); out.close(); }
From source file:ScanXan.java
public static void main(String[] args) throws IOException { Scanner s = null; try {// w ww.j a v a 2s. c o m s = new Scanner(new BufferedReader(new FileReader("xanadu.txt"))); while (s.hasNext()) { System.out.println(s.next()); } } finally { if (s != null) { s.close(); } } }