黑马程序员_打开文件 保存文件 菜单栏 打开之后显示到textArea 并能将taxtarea保存到文件中
来源:互联网 发布:淘宝卖家最高等级 编辑:程序博客网 时间:2024/06/10 12:04
---------------------- <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! ----------------------
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class practice27
{
private Frame f;
private File fe;
private MenuBar mb;
private Menu m;
private MenuItem mload,msave,mclose;
private TextArea ta;
practice27()
{
ini();
}
public void ini()
{
f=new Frame();
ta=new TextArea();
mb=new MenuBar();
m=new Menu("文件");
mload=new MenuItem("打开");
msave=new MenuItem("保存");
mclose=new MenuItem("关闭");
f.setBounds(200,100,500,400);
f.setLayout(new FlowLayout());
f.add(ta);
f.setMenuBar(mb);
mb.add(m);
m.add(mload);
m.add(msave);
m.add(mclose);
method();
f.setVisible(true);
}
public void method()
{
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
mclose.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
mload.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
FileDialog fdg=new FileDialog(f,"",FileDialog.LOAD);
fdg.setVisible(true);
String dirpath=fdg.getDirectory();
String filepath=fdg.getFile();
if(dirpath==null||filepath==null)
return;
ta.setText("");
fe=new File(dirpath+filepath);
String line;
BufferedReader bis=new BufferedReader(new InputStreamReader(new FileInputStream(fe)));
while((line=bis.readLine())!=null)
{
//String sb=new String(b,0,len);
ta.append(line+"\r\n");
System.out.println(ta.getText());
}
}
catch (Exception ex)
{
throw new RuntimeException("。。。。");
}
}
}
);
msave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try
{
String textstr=ta.getText();
if(fe==null)
{
FileDialog fdg=new FileDialog(f,"",FileDialog.SAVE);
fdg.setVisible(true);
String dirpath=fdg.getDirectory();
String filepath=fdg.getFile();
if(dirpath==null||filepath==null)
return;
else{
fe=new File(dirpath,filepath);}}
PrintStream ps=new PrintStream(new FileOutputStream(fe),true);
ps.println(textstr);
}
catch (Exception ex)
{
throw new RuntimeException(";;;;");
}
}
});
}
public static void main(String[] args)
{
new practice27();
}
}
---------------------- <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! ----------------------
- 黑马程序员_打开文件 保存文件 菜单栏 打开之后显示到textArea 并能将taxtarea保存到文件中
- 输入一个整数,将此整数保存到文件中,以记事本打开,显示同样的内容
- 将上传的文件描述保存到数据库中,并显示到页面
- Android 打开文件后向文件写数据,但数据并不能实时保存到磁盘
- Excel保存文件不能直接打开,打开之后显示灰屏,从左上角的文件中,再找到要打开的文件才能打开?
- 将文件保存到数据库中
- 将文件保存到数据库中(stream)
- C#将文件保存到数据库中
- 将文件保存到数据库中
- 将文件保存到数据库中
- 将文件保存到数据库中
- 将文件保存到sdCard中去
- 将数据保存到文件中
- 将日志保存到文件中
- 将对象保存到文件
- android 打开系统相机拍照并保存文件,显示图片。
- 通过添加按钮打开文件选取歌曲,并且添加到列表中(listbox)并保存在数据库中
- 黑马程序员_打开文件 存储文件
- 解决centOS下xxx is not in the sudoers file 问题
- c++复杂度
- Spring与Quartz使用说明
- opencv 检测直线、线段、圆、矩形
- MTK 短信
- 黑马程序员_打开文件 保存文件 菜单栏 打开之后显示到textArea 并能将taxtarea保存到文件中
- 黑马程序员_(UDP-聊天)
- 判断是否存在可用SIM卡:mmi_idle_get_dual_sim_status
- 调用长连接
- Linux Mysql 卸载/局域网访问权限
- Struts2文件下载
- Mars老师的Android学习基本路线_Java
- java try catch必须成对使用,否则报错
- Linux挂载Windows分区应硬盘