lbssy
发贴: 3
积分: 0
|
于 2008-04-04 21:12
import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; public class CopyFileChar extends JFrame implements ActionListener{ JTextField t1=new JTextField(30); JTextField t2=new JTextField(30); JButton btn=new JButton("复制"); CopyFileChar() { JPanel p1=new JPanel(); p1.add(new JLabel("源文件")); p1.add(t1); JPanel p2=new JPanel(); p2.add(new JLabel("目标文件")); p2.add(t2); JPanel p3=new JPanel(); p3.add(btn); this.getContentJPane().setLayout(new GridLayout(3,1)); this.getContentJPane().add(p1); this.getContentJPane().add(p2); this.getContentJPane().add(p3); btn.addActionListener(this); setTitle("用字符流复制文件"); setSize(450,150); setVisible(true);} public void actionPerformed(ActionEvent e){ try{ File inputFile=new File(t1.getText()); File outputFile=new File(t2.getText()); FileReader in=new FileRead(inputFile); FileWriter out=new FileWrite(outputFile); int c; while((c=in.read())!=-1)out.write; in.close(); out.close(); JOptionPane.showMessageDialog(null,"复制成***!");} catch(IOException ee) {System.err.println(ee);}} public static void main(String[] args) throws IOException{ JFrame.setDefaultLookAndSeeDecorated(true); Font font=new Font("JFrame",Font.PLAIN,14); Enumeration keys=UIManager.getLookAndFeelDefault().keys();} while(keys.hasMoreElements()){ Object key=keys.nextElement(); if(UIManager.get(key)instanceof Font) UIManager.put(key,font);} new CopyFileChar();}}
lbssy edited on 2008-04-04 21:16
|