怎么让这个简单JAVA程序读写中
//改过的地方已经标注
import 。*;
import t。*;
import javax。swing。*;
import t。event。*;
public class Welcome extends JFrame implements ActionListener{
private JTextArea ioTextArea;
private JButton saveButton,openButton;
private JLabel label;
private FileInputStream inFile;
private FileOutputStream outFile;
...全部
//改过的地方已经标注
import 。*;
import t。*;
import javax。swing。*;
import t。event。*;
public class Welcome extends JFrame implements ActionListener{
private JTextArea ioTextArea;
private JButton saveButton,openButton;
private JLabel label;
private FileInputStream inFile;
private FileOutputStream outFile;
private DataOutputStream dos;//////////////////////////////
private DataInputStream dis;///////////////////////////////
private File file;
byte[] bufferArray=new byte[4096];
public Welcome(){
Container container=getContentPane();
tLayout(new FlowLayout());
label=new JLabel("文本显示及编辑区:");
tForeground( d);
d(label,BorderLayout。
NORTH);
ioTextArea=new JTextArea("",10,20) ;
tEditable(true) ;
d(new JScrollPane(ioTextArea),BorderLayout。
CENTER);
saveButton=new JButton("Save") ;
d(saveButton,BorderLayout。EAST);
dActionListener(this);
openButton=new JButton("Open") ;
d(openButton,BorderLayout。
WEST);
dActionListener(this);
setSize(300,300);
setVisible(true);
}
public void actionPerformed(ActionEvent event){
if( tSource()==saveButton){
try{
outFile=new FileOutputStream(new File("test。
txt"));
dos = new DataOutputStream(outFile);///////////////////////////
dos。writeUTF( tText());/////////////////////////////
ose();//////////////////////////////////////////////////
owMessageDialog(this,"内容已保存到test。
txt!");
}
catch(IOException e) {
owMessageDialog(this,"写入错误!","Error",JOptionPane。ERROR_MESSAGE);
System。
exit(1);
}
}
else if( tSource()==openButton){
try{
file=new File("test。txt");
int fileLength=(int)file。
length();
inFile=new FileInputStream(file);
dis = new DataInputStream(inFile);///////////////////////
String str=new String();
str = adUTF();////////////////////////////////////
tText(str);
ose();
owMessageDialog(this,"文件已打开!");
}
catch(IOException e) {
owMessageDialog(this,"文件打开关闭时发生错误!","Error",JOptionPane。
ERROR_MESSAGE);
System。exit(1);
}
}
}
public static void main(String args[]) {
Welcome welcome=new Welcome();
tDefaultCloseOperation(JFrame。
EXIT_ON_CLOSE);
}
}。收起