import javax.swing.*;
import java.io.*;
public class FileIO{
public static void main (String args [])throws IOException{
String input = JOptionPane.showInputDialog("Enter FileName: ");
File x = new File(input);
File f = new File ("d:\\aa\\bb\\");
f.mkdirs();
FileWriter text = new FileWriter (f + "\\grades.txt");
text.write("90");
text.write("91");
text.write("92");
text.write("93");
text.write("94");
text.close();
if (f.exists()){
System.out.println(f.getPath() + " exist");
} else {
System.out.println(f.getPath() + " does not exist");
}
//getting the average of the input grades from grades.txt
/* int sum = 0, ctr=0;
while(val != null){
ctr++;
sum += Integer.parseInt(val);
val = x.readLine();
}
System.out.println("Ave = " + sum/ctr);
f.close();*/
}
}
Hello. I like to ask for your help. I need to check if the file input by the user is on the folder. And afterwards use the content of that so compute for the next set of codes. For example, a list of grades was input on the notepad. Example:
grades.txt: 90 91 92 93 94
Sample Output:
grades.txt exist in the directory
Grade Average: Ave = 92