Code example for Scanner

Methods: hasNextLinenextLine

0
	 * 
	 * @return hasUnreadMembers - boolean. 
	 */ 
	public boolean hasNextMember() { 
		if (this.hasOpenLocation())
			return this.scanner.hasNextLine();
		else 
			return false; 
	} 
 
	/** 
	 * Determine if a location has been opened for reading. 
	 * 
	 * @return hasOpenLocation - boolean. 
	 */ 
	public boolean hasOpenLocation() { 
		return (this.scanner != null);
	} 
 
	/** 
	 * Open a given location for prior to reading contents. This operation must 
	 * succeed before the other reading operations may be executed successfully. 
	 * 
	 * @param targetLocation 
	 *            File. 
	 * @return success - boolean. 
	 */ 
	public boolean openLocation(final File targetLocation) {
		try { 
			this.scanner = new Scanner(new FileInputStream(targetLocation),
					"UTF-8"); 
			return true; 
		} catch (final Exception exception) {
			this.logger.exception("Unable to Open Location [" + targetLocation
					+ "].", exception);
			return false; 
		} 
	} 
 
	/** 
	 * Return a the contents of the location as bytes. Typically used for 
	 * fingerprinting purposes - However, may cause a problem with large files. 
	 * 
	 * @param targetLocation 
	 *            File. 
	 * @return contentBytes - byte[]. 
	 */ 
	public byte[] readContentsBytes(final File targetLocation) {
		byte[] contentBytes = new byte[0];
		BufferedInputStream bis = null;
		try { 
			bis = new BufferedInputStream(new FileInputStream(targetLocation));
			contentBytes = new byte[(int) targetLocation.length()];
			bis.read(contentBytes);
		} catch (final Exception e) {
			this.logger.exception("Unable to Read Contents Bytes ["
					+ targetLocation + "].", e);
		} finally { 
			try { 
				bis.close();
			} catch (final Exception e) {
				this.logger
						.exception( 
								"Unable to Close Storage BufferedInputStream During readContentsBytes.", 
								e);
			} 
		} 
		return contentBytes;
	} 
 
	/** 
	 * Read the next member of the contents. Within files members are considered 
	 * lines and this command will return the next line. 
	 * 
	 * @return nextMember - String. 
	 */ 
	public String readNextMember() {
		if (!this.hasOpenLocation()) {
			this.logger.warning("Attempting to Read Without Closed Location.");
			return new String();
		} else if (!this.hasNextMember()) {
			this.logger.warning("Reading While Has No More Content.");
			return new String();
		} else 
			return this.scanner.nextLine();
	} 
 
	/** 
	 * STORAGE WRITING OPERATIONS *********************************************. 
	 *  
Contextual code suggestions in your IDE  Get Codota for Java