标题:[求助]程序运行时出错
取消只看楼主
Algorithms
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-1
 问题点数:0 回复次数:0 
[求助]程序运行时出错

import java.awt.*;
import java.io.*;
import javax.swing.*;
//import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.filechooser.FileFilter;
public class test extends JFrame
{

static int result;
static JFileChooser jf;
JButton jbt;

public test()
{
Container cp=getContentPane();
cp.setLayout(new FlowLayout(1));
jf=new JFileChooser();
jbt=new JButton("打开文件");
jf.setFileFilter(new FFT());
jbt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
result=jf.showOpenDialog(null);
}
}
);

cp.add(jbt);




setSize(400,400);
setVisible(true);

}
public static void main(String[]args)throws IOException
{
File file=null;
String name;
test ap=new test();
ap.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

if(result == JFileChooser.APPROVE_OPTION)
{
file = jf.getSelectedFile();



FileInputStream f=new FileInputStream(file);
int n=f.available();
byte[] b=new byte[n];

while(f.read(b)==-1)
return;
String str=new String(b);

System.out.print(str);

f.close();
}

}
}
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文件";
}
}

搜索更多相关主题的帖子: 运行 
2006-12-28 01:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-112615-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.289288 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved