⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example20_6.java

📁 不错的教程 适合中高级人员的使用
💻 JAVA
字号:
import  java.io.*;import java.awt.*;import java.awt.event.*;class EWindow extends Frame implements ActionListener{  TextArea text;    Button buttonRead,buttonWrite;   BufferedReader bufferIn;    FileReader in;   BufferedWriter bufferOut;    FileWriter out;   EWindow()   {  super("流的读取");      text=new TextArea(10,10);text.setBackground(Color.cyan);      buttonRead =new Button("读取");       buttonRead.addActionListener(this);      buttonWrite =new Button("写出");       buttonWrite.addActionListener(this);      setLayout(new BorderLayout());      setSize(340,340);      setVisible(true);      add(text,BorderLayout.CENTER);      Panel pNorth=new Panel();      pNorth.add(buttonRead);pNorth.add(buttonWrite);      pNorth.validate();      add(BorderLayout.NORTH,pNorth);      addWindowListener(new WindowAdapter()                       {  public void windowClosing(WindowEvent e)                            {  System.exit(0);                            }                       });   }    public void actionPerformed(ActionEvent e)   {  String s;      if(e.getSource()==buttonRead)       {  try{  text.setText(null);                File f=new File("Example20_6.java");                in=new FileReader(f);                bufferIn=new BufferedReader(in);                while((s=bufferIn.readLine())!=null)                 {  text.append(s+'\n');                    }                bufferIn.close();                in.close();             }          catch(IOException exp){System.out.println(exp);}        }      if(e.getSource()==buttonWrite)       {  try {  File f=new File("Example20_6(out).java");                 FileWriter out=new FileWriter(f);                 BufferedWriter bufferOut=new BufferedWriter(out);                 bufferOut.write(text.getText(),0,(text.getText()).length());                 bufferOut.flush();                 bufferOut.close();                 out.close();               }          catch(IOException exp){  System.out.println(exp);}       }   }}public class Example20_6{  public static void main(String args[])   {  EWindow w=new EWindow();      w.validate();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -