import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
public class test extends JFrame
{
static int result;
static JFileChooser jf;
public test()
{
Container cp=getContentPane();
jf=new JFileChooser();
jf.setFileFilter(new FFT());
result=jf.showOpenDialog(null);
setSize(400,400);
setVisible(true);
}
public static void main(String[]args)
{
String name;
test ap=new test();
ap.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if(result == JFileChooser.APPROVE_OPTION)
{
File file = jf.getSelectedFile();
}
try{
FileInputStream f=new FileInputStream(file);
int d=f.read();
while(f.read()!=-1)
{
char c=(char)d;
d=f.read();
System.out.print(c);
}
}
catch(IOException ex)
{
}
}
}
class FFT extends FileFilter
{
public boolean accept(File f)
{
if(f.getPath().endsWith(".txt")||f.isDirectory())
return true;
else
return false;
}
public String getDescription()
{
return "txt文件";
}
}