import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;
public class duqu extends JFrame implements ActionListener,WindowListener
{
private JTextField text1,text2;//分别为要扫描的磁盘,和扫描后把文件读到目标磁盘。
private JButton button;
public duqu()
{
 super("秘密读取");
 this.setBounds(200,200,200,200);
 this.setDefaultCloseOperation(EXIT_ON_CLOSE);
 this.getContentPane().setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));
 
 text1=new JTextField("",10);
 text2=new JTextField("",10);
 button=new JButton("确定");
 this.add(new JLabel("读取的盘符"));
 this.add(text1);
 this.add(new JLabel("输出的盘符"));
 this.add(text2);
 this.add(button);
 button.addActionListener(this);
 
 this.addWindowListener(this);
 this.setVisible(true);
}
public void windowClosing(WindowEvent e)
{}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void actionPerformed(ActionEvent e)
{
 if(e.getSource()==button)
 {
  //if(text1.getText().equals("f"))
  //{
  //int i;
  //saomiao  s=new saomiao();
  //String name[]=new String[s.qqname.length];
  try
  {
  File f=new File("f:/1.txt");
  File f1=new File("c:/2.txt");
  FileInputStream reader1=new FileInputStream(f);
  FileOutputStream writer1=new FileOutputStream(f1);
  int count=1;
  
  while(count!=-1)
  {   byte[] buffer=new byte[1];
    count=reader1.read(buffer);   
    writer1.write(buffer);     
    System.out.print(buffer);  
  }
   writer1.close();
   reader1.close();
  }
  catch(Exception e3){e3.printStackTrace();}
  
  //for(int ii=0;ii<s.qqname.length;ii++)
  //{
  // System.out.println(s.qqname[ii]);
  // try
  // {
   /*File f=new File("j:/"+s.qqname[ii]);
   File f1=new File("c:/"+s.qqname[ii]);
   FileInputStream reader1=new FileInputStream(f);
   FileOutputStream writer1=new FileOutputStream (f1);
   int count=0;
   byte[] buffer=new byte[512];
   while(count!=-1)
   {
    
    count=reader1.read();
    if(count!=-1)
    {
    writer1.write(buffer);
    System.out.print(count);
    }
   } */
  
  // }
  // catch(Exception e1){e1.printStackTrace();}
   
  //}
  //}
  
 //}
 // else 
 //  JOptionPane.showMessageDialog(this,"输入错误请重新输入");
 }
 
}
public static void main(String []args)
{
 new duqu();
}
}
class saomiao 
{
    int count_dirs=0, count_files=0;                       //目录数和文件数
    int j=0;
    long byte_files=0;                                     //所有文件总字节数 
    public String qqname[];
    public saomiao()
    {
        count(new File("j:/",""));                              //创建当前目录
        System.out.println("共有 "+count_files+" 个文件,总字节数为 "+byte_files);
        System.out.println("共有 "+count_dirs+" 个目录");
    }
    public void count(File dir)                            //dir目录中文件列表,递归算法
    {
        System.out.println(dir.getAbsolutePath());         //显示dir的绝对路径
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
        File[] files = dir.listFiles();   //返回当前目录中所有文件       
        qqname=new String[files.length];
        int jj=0;
        for (int i=0; i<files.length; i++)                 //目录和文件列表
        {
            System.out.print(files[i].getName()+"\t");     //显示文件名           
            if (files[i].isFile())                         //判断指定File对象是否是文件
            {
                 System.out.print(files[i].length()+"B\t");//显示文件长度
                 count_files++;                 
                 byte_files += files[i].length();                
                 j++;                
                 qqname[jj]=files[i].getName();
                 jj++;
            }
            else
            {
                 System.out.print("<DIR>\t");
                 count_dirs++;
            }
            System.out.println();//显示文件修改时间
        }
        System.out.println();
      
     }
} 原来的文件如果是12字节的话,为什么生成的文件会多一个字节呢?