关于io的小问题,请指点 byte[] b=strCount.getBytes();tyr{FileOutputStream outputfile =new FileOutputStream("albert.txt");outputfile1.write(b);}....... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给个演示程序你吧:import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;public class Frame1{ public static void main(String[] args) { JFrame frame = new SaveFrame(); frame.show(); }}class SaveFrame extends JFrame{ private JTextField number; private JButton saveButton; private JButton readButton; private String fileName="count.txt"; public SaveFrame() { this.setTitle("operation on "+fileName); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); number = new JTextField("20",30); saveButton = new JButton("save"); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if(number.getText().length()<=0) return; try { DataOutputStream dos=new DataOutputStream( new FileOutputStream(new File(fileName))); dos.writeUTF(number.getText()); dos.close(); } catch(IOException e) { e.printStackTrace();} } }); readButton = new JButton("read from file"); readButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { DataInputStream dis=new DataInputStream( new FileInputStream(new File(fileName))); number.setText(dis.readUTF()); dis.close(); } catch(IOException e){ e.printStackTrace(); } } }); this.getContentPane().setLayout(new FlowLayout()); this.getContentPane().add(number); this.getContentPane().add(saveButton); this.getContentPane().add(readButton); this.pack(); }} 有一个write()和一个flush()方法,你可以看一下帮助 错哪了~~ 向前辈们请教:关于连接SQL2000数据库的问题! JAVA新手遇到的程序问题 这个测试的结果为什么是这样呢? 在javaeye的论坛上问了居然没一人回复,回来请教CSDN的各位高手,prepareStatement中使用in 的问题 请问java中获得一个Graphics()对象的方法有哪些?? 如何给浮点型的数据限制小数点后的位数 菜鸟问题 cmd中显示不了java程序中的中文字 请教:哪位做过基于CORBA的程序 Jtable如何设置焦点? 如何将Delphi中的加密解密程序改写java的加密解密程序?(源代码奉献,问题解决分可以再加)
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;public class Frame1
{
public static void main(String[] args)
{
JFrame frame = new SaveFrame();
frame.show();
}
}
class SaveFrame extends JFrame
{
private JTextField number;
private JButton saveButton;
private JButton readButton;
private String fileName="count.txt"; public SaveFrame()
{
this.setTitle("operation on "+fileName);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
number = new JTextField("20",30);
saveButton = new JButton("save");
saveButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(number.getText().length()<=0) return;
try
{
DataOutputStream dos=new DataOutputStream(
new FileOutputStream(new File(fileName)));
dos.writeUTF(number.getText());
dos.close();
}
catch(IOException e) { e.printStackTrace();}
}
});
readButton = new JButton("read from file");
readButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
DataInputStream dis=new DataInputStream(
new FileInputStream(new File(fileName)));
number.setText(dis.readUTF());
dis.close();
}
catch(IOException e){ e.printStackTrace(); }
}
});
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(number);
this.getContentPane().add(saveButton);
this.getContentPane().add(readButton);
this.pack();
}
}