[General boards] [Fall 2018 courses] [Summer 2018 courses] [Winter 2018 courses] [Older or newer terms]

PCRS / file / part2


#1

I don’t know why this wouldn’t work, it work on my computer, but not in PCRS???
Compile Error:
BufferedReaderExercise.java:28: error: cannot find symbol
in = new BufferedReader(new FileReader(path));
^
symbol: variable path
location: class BufferedReaderExercise
1 error

Below is my code

import java.io.*;

public class BufferedReaderExercise {
public static int sumLineByLine(String path) throws IOException {
int sum = 0;
BufferedReader in = null;

    try {
        in = new BufferedReader(new FileReader(path));
			 if (in.readLine().trim().length() == 0) {
        	sum = 0;
        	in.close();
        } else {
        	in = new BufferedReader(new FileReader(path));
        	while (in.ready()){
        		String temp = in.readLine();
        		int a = Integer.parseInt(temp);
        		sum = sum + a;
            }
        }
    } finally {
        if (in != null) {
            in.close();
        }
    }

    return sum;
}

}