So I have this code that pops up a file chooser and reads the file:
JFileChooser chooser = new JFileChooser();
File file = null;
int returnValue = chooser.showOpenDialog( null ) ;
if( returnValue == JFileChooser.APPROVE_OPTION ) {
file = chooser.getSelectedFile() ;
}
if(file != null) {
String filePath = file.getPath();
}
// String filePath (that's what i'm trying to input) = "Users/Bill/Desktop/hello.txt";
try {
ReadFile files = new ReadFile(***);
String[] lines = files.OpenFile();
the three asterisks (*) represent the class path of the file to be read. What should I put there if I want to read the file? Before this, I hard-coded the class-path and passed it in and it worked, but now, the class-path can be whatever the user chooses. Thanks for your help!
I don’t know what your
ReadFilething is, but it looks like it takes a string representing the file path. In which case, you probably want to give itfile.getPath().