public class JFilechooserDemo{
public static void main(String[] args) throws IOException{
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if(returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
BufferedReader reader=new BufferedReader(new FileReader(chooser.getSelectedFile()));
String line;
StringBuilder sb = new StringBuilder();
while((line=reader.readLine())!=null){
sb.append(line);
}
reader.close();
System.out.println(sb.toString());
}
}