import java.awt.FlowLayout;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
ReadAndWriteText(){
btnpnl.add(Read);
btnpnl.add(Save);
Read.addActionListener(this);
Save.addActionListener(this);
this.add(btnpnl);
this.add(text);
this.setBounds(450, 150, 300, 400);
this.setVisible(true);
this.validate();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private void save()
{
System.
out.
println(file.
getAbsolutePath());//获得绝对路径
try {
str=text.getText();
bfw.write(str, 0, str.length());
bfw.flush();
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
private void read() {
// TODO Auto-generated method stub
try {
while((str=bfr.readLine())!=null){
text.append(str+"\n");
}
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
// TODO Auto-generated method stub
if(Save==e.getSource()){
save();
}
if(Read==e.getSource()){
read();
}
}
public static void main
(String []args
){
new ReadAndWriteText();
// System.out.println((new SimpleDateFormat("yyyy-MM-dd HH:mm:ssss")).format(time2));
}
}
//java/1347