用JAVA写的电子书切割器 欢迎修改意见至wmm204@126.com

来源:互联网 发布:知错老师的微博 编辑:程序博客网 时间:2024/05/12 18:24
 /*下面是电子书切割器源代码 被切割文件要和切割器在同一目录*/import java.awt.*;import java.awt.event.*;import java.io.*;public class TextCut extends Frame implements ActionListener,WindowListener{static TextCut f=new TextCut();static TextField fileName=new TextField("文件名字",20);static TextField fileSize=new TextField("切割后文件大小",20);static Button btn=new Button("开始切割");static String fname=""; static String fsize="";public static void main(String[] args){    f.setSize(200,150);   f.setTitle("my text cut");   f.setLayout(new FlowLayout(FlowLayout.CENTER));   fileName.addActionListener(f);   fileSize.addActionListener(f);   btn.addActionListener(f);                                     f.addWindowListener(f);   f.add(fileSize);   f.add(fileName);   f.add(btn);   f.setVisible(true); }public void textValueChanged(TextEvent e){  }                   public void windowActivated(WindowEvent e) //活动窗口{}public void windowClosed(WindowEvent e) //窗口关闭{}public void windowClosing(WindowEvent e)//按下窗口关闭钮{   f.dispose();   System.exit(0);}public void windowDeactivated(WindowEvent e) //变成非活动窗口{}public void windowDeiconified(WindowEvent e) //窗口还原{}public void windowIconified(WindowEvent e) //窗口最小化{}public void windowOpened(WindowEvent e) //窗口打开{}public void actionPerformed(ActionEvent e){   Button b=(Button)e.getSource();   if(b==btn){   fname=fileName.getText();   fsize=fileSize.getText();   qiege();   }}public static void qiege(){try{     int ch;    int l=Integer.parseInt(fsize);    int len=fname.length();     FileInputStream fin=new FileInputStream(fname);       for(int j=1;j>0;j++)      {      if(fin.read()==-1)   break;           else{        StringBuffer newName=new StringBuffer(fname);        newName.insert((len-4),String.valueOf(j));        String Name=new String(newName);        for(int i=0;i<l;i++){        ch=fin.read();     FileOutputStream fout=new FileOutputStream(Name,true);     fout.write(ch);        }          }          }    }catch(Exception e){}}} 正学到java输入与输出流 就写了这个东西 想挑战下自己从构思到写好花了1星期。高手别笑 ,小弟才学的java。虽然界面还是很粗糙的,可修改的地方也很多,我还是蛮高兴的。切割后会有乱码,是为什么啊?欢迎批评和指点!!
原创粉丝点击