
How to open a file in java using JFileChooser

import java.io.*;
import javax.swing.*;
class OpenFileUsingJFileChooser{
public static void main(String[] args)throws Exception{
JFileChooser chooser=new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
BufferedReader br=new BufferedReader(new FileReader(f));
String st="";
while((st=br.readLine())!=null){
System.out.println(st);
}
}
}
}

I just tried to use this portion of code and it just reprints the string that was entered in my file to the command prompt. I cannot figure out how to change it to actually open the file I select rather than printing it's contents back to the console.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.