将获取到的文本框的值写入到文件 怎样将获取到的文本框的值写入到文件中,能在我的代码上加上这个功能或写一个实例吗?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 printwriter pw=new printwriter(new filewriter("文件路径"),true);pw.writer(textname.getparameter());不知道对不对,试一下吧 import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;public class TextAreaDemo extends JFrame implements ActionListener{ JTextArea ta=new JTextArea(10,10); JLabel j=new JLabel("准备写入"); JButton b=new JButton("确定写入"); JPanel p=new JPanel(); public TextAreaDemo(){ p.add(ta); p.add(j); p.add(b); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setContentPane(p); this.setTitle("信息录入器"); this.setSize(400,200); this.setVisible(true); b.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource().equals(b)) { try{ PrintWriter out=new PrintWriter(new FileWriter("area.txt",true)); String str=ta.getText(); out.println(str); out.close(); j.setText("已经写入"); }catch(Exception ex){ System.out.println(ex); } } } public static void main(String[] args){ new TextAreaDemo(); }} 为什么是false eclipse的右键菜单项如何清理? 关于Java中静态变量和静态方法的问题 jdk1.4后不用在配置CLASSPATH的变量了吗?? udp协议的接收问题,急 JTable更新的奇怪问题! 一个关于Date的问题 如何将applet的jar文件中包含的其它文件复制到客户端的机器上 初学JAVA,麻烦大家推荐编译器 如何在控件上按右键弹出自己的菜单?有具体例子吗? 线程的初始化问题.多线程调用.财务系统. applet换个机器,不能正常显示,这是怎么回事?
pw.writer(textname.getparameter());不知道对不对,试一下吧
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class TextAreaDemo extends JFrame implements ActionListener{
JTextArea ta=new JTextArea(10,10);
JLabel j=new JLabel("准备写入");
JButton b=new JButton("确定写入");
JPanel p=new JPanel();
public TextAreaDemo(){
p.add(ta);
p.add(j);
p.add(b);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setContentPane(p);
this.setTitle("信息录入器");
this.setSize(400,200);
this.setVisible(true);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(b))
{
try{
PrintWriter out=new PrintWriter(new FileWriter("area.txt",true));
String str=ta.getText();
out.println(str);
out.close();
j.setText("已经写入");
}catch(Exception ex){
System.out.println(ex);
}
}
}
public static void main(String[] args){
new TextAreaDemo();
}
}