Question: So when I run the program, I get the error file not found. Im working with a MacBook and I have my Numbers.txt file save

So when I run the program, I get the error file notfound. Im working with a MacBook and I have my Numbers.txt filesave on my desktop. Please help. 69 import java.util.Scanner; 2 // TASK#3 Add the file 1/0 import statement here 3 import java.io. BufferedReader;So when I run the program, I get the error file not found. Im working with a MacBook and I have my Numbers.txt file save on my desktop. Please help.

69 import java.util.Scanner; 2 // TASK #3 Add the file 1/0 import statement here 3 import java.io. BufferedReader; 2. import java.io.FileNotFoundException; 5 import java.io.FileReader; 6 import java.io.FileWriter; 7 import java.io.IOException; 8 import java.io.PrintWriter; SA import java.text.DecimalFormat; 10 9 /** 11 This class reads numbers from a file, calculates the 12 mean and standard deviation, and writes the results 13 to a file. 14 */ 15 16 public class StatsDemo 17 { 18 // TASK #3 Add the throws clause 19 public static void main(String[] args) throws IOException { 20 { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the numbers double stdDev = 0; // The standard deviation 25 String line; // To hold a line from the file 26 double difference; // The value and mean difference 27 28 // Create an object of type Scanner 29 Scanner keyboard = new Scanner (System.in); 30 String filename; // The user input file name 31 32 // Prompt the user and read in the file name 33 System.out.println("This program calculates " + 34 "statistics on a file " + 35 "containing a series of numbers"); 111 35 "containing a series of numbers"); 36 System.out.print("Enter the file name: "); 37 filename = keyboard.nextLine(); 38 39 // ADD LINES FOR TASK #4 HERE 40 // Create a FileReader object passing it the filename 41 // Create a BufferedReader object passing FileReader 42 // object 43 // Perform a priming read to read the first line of 44 // the file 45 // Loop until you are at the end of the file 46 1/ Convert the line to a double value and add the 47 // value to sum 48 // Increment the counter 49 // Read a new line from the file 50 // Close the input file 51 // Store the calculated mean 52 A FileReader fw=new FileReader(filename); 54 BufferedReader br = new BufferedReader(fw); String tem 56 while ((tem=br.readLine()) != null) { 57 sum=sum+ Double.parseDouble(tem); 58 count++; 59 } 60 fw.close(); 61 mean= sum/ count; 62 System.out.print(" Mean= "+mean); 63 64 // ADD LINES FOR TASK #5 HERE 65 // Reconnect FileReader object passing it the 66 // filename 67 // Reconnect BufferedReader object passing 68 // FileReader object 69 // Reinitialize the sum of the numbers Stats Demo main > keyboard > FileReader fr=new FileReader(filename); BufferedReader brr = new BufferedReader(fr); sum=0; count=0; while ((tem=brr.readLine()) != null) { difference = mean-Double.parseDouble(tem); sum= sum+ difference*difference; count++; } stdDev= Math.sqrt(sum / count); System.out.println(" Standard deviation: %.3f "); fr.close(); 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 A 106 107 // ADD LINES FOR TASK #3 HERE // Create a FileWriter object using "Results.txt" // Create a PrintWriter object passing the // FileWriter object // Print the results to the output file // Close the output file FileWriter f=new FileWriter("Results.txt"); PrintWriter pw = new PrintWriter(f); line=String.format("%.3f",stdDev) ;; pw.print(line); pw.print(" "); line=String.format("%.3f", mean);; pw.print(line); pw.close(); 109 110 111 112 113 114 } } run: This program calculates statistics on a file containing a series of numbers Enter the file name: /Volumes/reybaltazar/Numbers.txt Exception in thread "main" java.io.FileNotFoundException: /Volumes/reybaltazar/Numbers.txt (No such file or directory) at java.io.FileInputStream.open(Native Method) | at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.(FileInputStream.java:138) at java.io.FileInputStream.(FileInputStream.java:93) at java.io.FileReader.(FileReader.java:58) at StatsDemo.main(StatsDemo.java:53) /Users/reybaltazar/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1 BUILD FAILED (total time: 30 seconds)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!