import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class DisplayFile {
/**
* @param args
*/
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
JFrame frame =new JFrame("Display File");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea ta=new JTextArea(20,30);
JFileChooser chooser=new JFileChooser();
int status =chooser.showOpenDialog(null);
if(status!=JFileChooser.APPROVE_OPTION)
ta.setText("No file chosen!");
else
{
File file=chooser.getSelectedFile();
Scanner scan=new Scanner(file);
String info="";
while(scan.hasNext())
info+=scan.nextLine();
ta.setText(info);
frame.getContentPane().add(ta);
frame.pack();
frame.setVisible(true);
}
}
}