Code example for Scanner

Methods: close, hasNextLine, nextLine

0
	/** 
	 * Attempt to parse a string using a closed Scanner. 
	 */ 
	public static void writeToClosedStream(){ 
		try{ 
			Scanner in = new Scanner(System.in);
			System.out.println("Enter something: ");
			if (in.hasNextLine()){
				String myStr = in.nextLine();
				if(myStr.contains("something")){
					System.out.println("You entered something!");
				} 
				else{ 
					System.out.println("You didn't enter \"something\". Haha...");
				} 
			} 
			in.close();
			in.nextLine();
		}catch (IllegalStateException e){
			e.printStackTrace();
		} 
	}