输入输出的问题?(请问这个程序怎么结束)

t427795737 2007-10-12 05:51:08
这个程序是我自己写的,能编译也能按我预期的目的运行,但是我不知道什么结束程序,把输入输出流关了还是不能结束,我只有关闭了控制台窗口才能终止程序
import javax.swing.*;
import java.io.*;

public class InputStudentInfo
{
public static void main(String[] args)
{
………………
{
FileOutputStream fout = new FileOutputStream(myFile);
DataOutputStream dos = new DataOutputStream(fout);
JFrame frame = new JFrame();
frame.setVisible(true);
str = JOptionPane.showInputDialog(frame, "Your name?");
dos.writeUTF("name:" + str);
str = JOptionPane.showInputDialog(frame, "Your sex?");
dos.writeUTF("sex:" + str);
str = JOptionPane.showInputDialog(frame, "Your age");
dos.writeUTF("age:" + str);
fout.close(); // MARK!!!!!!!
FileInputStream fis = new FileInputStream(myFile);
DataInputStream dis = new DataInputStream(fis);
System.out.println(dis.readUTF());
System.out.println(dis.readUTF());
System.out.println(dis.readUTF());
fis.close(); // MARK!!!!
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}
...全文
108 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunyujia 2007-10-14
  • 打赏
  • 举报
回复
cs程序有界面的,就像qq一样一定要用户点击按钮才能关闭啊,
你可以写个事件,事件里面执行System.exit(1);就可以了.
joejoe1991 2007-10-14
  • 打赏
  • 举报
回复
最后加一个System.exit(1);就可以退出了
awaltz 2007-10-13
  • 打赏
  • 举报
回复
按“CTRL+C”就可以结束程序
B1977 2007-10-13
  • 打赏
  • 举报
回复
你是不是先要dis.flush();
fis.close();
tangxiaoqin 2007-10-13
  • 打赏
  • 举报
回复
因为frame的线程还在运行

可用System.exit(0);退出

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧