List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new File("c:/text.txt")); System.out.println(scanner.nextLine()); scanner.close();// ww w. ja va 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 locale of this scanner scanner.useLocale(Locale.US); // change the radix of this scanner scanner.useRadix(30);/*from w ww.j av a 2s.c o m*/ // reset and check the values for radix and locale, which are the default scanner.reset(); System.out.println(scanner.radix()); System.out.println(scanner.locale()); scanner.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new FileInputStream("c:/text.txt")); System.out.println(scanner.nextLine()); scanner.close();// w w w .j a v a 2 s .c o m }
From source file:Test.java
public static void main(String[] args) throws Exception { AsynchronousSocketChannel client = AsynchronousSocketChannel.open(); InetSocketAddress address = new InetSocketAddress("localhost", 5000); Future<Void> future = client.connect(address); System.out.println("Client: Waiting for the connection to complete"); future.get();//from www . ja v a2s . c o m String message = ""; while (!message.equals("quit")) { System.out.print("Enter a message: "); Scanner scanner = new Scanner(System.in); message = scanner.nextLine(); System.out.println("Client: Sending ..."); ByteBuffer buffer = ByteBuffer.wrap(message.getBytes()); System.out.println("Client: Message sent: " + new String(buffer.array())); client.write(buffer); } }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Scanner scanner = new Scanner(new StringReader(s)); System.out.println(scanner.nextLine()); // change the radix of the scanner scanner.useRadix(32);/*from w ww . j a va 2 s.c om*/ // display the new radix System.out.println(scanner.radix()); 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); // print the line System.out.println(scanner.nextLine()); // print the current locale System.out.println(scanner.locale()); scanner.close();/*from w w w . j a va 2 s. c o m*/ }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); // print the line System.out.println(scanner.nextLine()); // check if there is an IO exception System.out.println(scanner.ioException()); scanner.close();//from www. j a va 2 s.c o 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); scanner.skip("java2s"); System.out.println(scanner.nextLine()); scanner.close();/*from www. j a va2 s . c o m*/ }
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(); System.out.println(line); }/*from ww w.j a v a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { String s = "java2s.com \n 1 + 1 = 2.0 true "; Scanner scanner = new Scanner(s); // print the next line System.out.println(scanner.nextLine()); // print the next line again System.out.println(scanner.nextLine()); scanner.close();/*from www. j a va 2 s . c om*/ }