Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed FileIO #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Step1/ReadOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String[] args)
try {
// Create the Scanner object using the file
// as input
Scanner fileIn = new Scanner(new File("input.txt"));
Scanner fileIn = new Scanner(new File("/Users/dhannya/Projects/FileIOJava/Step1/input.txt"));

/* Loop while the file still has lines.
* .hasNext() looks to see if a line exists
Expand Down
16 changes: 11 additions & 5 deletions Step4/ReadFour.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package Step4;

import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class ReadFour
{
public class ReadFour {
/**
* Yes, you can look at the other
* Yes, you can look at the other
* examples in this lab to build your solution here.
*/
public static void main(String[] args)
{
public static void main(String[] args) throws FileNotFoundException {
Scanner scan = new Scanner(new File("/Users/dhannya/Projects/FileIOJava/Step4/input.txt"));
int sum = 0;
while (scan.hasNext()) {
int lineIn = Integer.parseInt(scan.nextLine());
sum = sum + lineIn;
System.out.println("Running total: " + sum);
// Print out a running total of all the
// values in the input file.
}
}
}