Skip to content

Project: FileReading

William Mueller edited this page Sep 20, 2019 · 1 revision

FileReading Program

Page for everything related to the FileReading project.

Important methods:

Creating a File Scanner

		try {
			inputReplaceFile = new Scanner(replacementFile);
		}
		catch(FileNotFoundException ex) {
			output.println("Part 3: Unable to Open File");
			output.close();
			System.exit(1);
		}

General Methods

  • boolean hasNextLine(); - returns true if there is another line in the stream
  • String nextLine(); - reads all characters from the current position up until the next newline character in the stream; returns a string of all of these characters
  • boolean hasNext(); - returns true if there is another token (a block of non-whitespace characters) in the stream
  • String next(); - returns a the next token in the stream as a string
  • boolean hasNextInt(); - returns true if the next token is an integer
  • int nextInt() - returns the next token in the stream as an int
  • boolean hasNextDouble(); - returns true if the next token is a double
  • double nextDouble(); - returns the next token in the stream as a double
  • void close(); - closes the file

Clone this wiki locally