Hello so for this problem i have to read a text file but for some reason it won't let me do it.
this is my code:
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class Assignment102 { public static void main(String[] args) { try { // Initialize min and max int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; // Construct a string with the name of the input file. You // can use this to construct an appropriate Reader object. String filename = "tai8.txt"; FileReader fis = new FileReader(filename); BufferedReader b = new BufferedReader(fis); String line; while ((line = b.readLine()) != null) { int number = Integer.parseInt(line.trim()); if (number < min) min = number; if (number > max) max = number; } b.close(); fis.close(); // Print the results System.out.println("Minimum value: " + min); System.out.println("Maximum value: " + max); } catch(Exception ioe) { ioe.printStackTrace(); } } }
when i compile it i get this error message:
java.io.FileNotFoundException: tai8.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:120)
at java.io.FileInputStream.<init>(FileInputStream.jav a:79)
at java.io.FileReader.<init>(FileReader.java:41)
at assignment.pkg10.pkg2.Assignment102.main(Assignmen t102.java:29)
i'm not sure how to put the text file in the same directory as the java file. maybe that's what the issue is? can someone please help me with this? Thank you.