这个程序是我自己写的,能编译也能按我预期的目的运行,但是我不知道什么结束程序,把输入输出流关了还是不能结束,我只有关闭了控制台窗口才能终止程序
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());
}
}
}
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());
}
}
}
fis.close();
你可以写个事件,事件里面执行System.exit(1);就可以了.