public void Catfile() {
        
        LogFile.Write("#BEGIN Catfile(): " + fi.getTenfile());
        fi.kiemTraVaTaoThuMuc("./" + ThongTinChunk.duongDanChunk + fi.getTenfile() + "/");
        fi.kiemTraVaTaoThuMuc("./torrent/");

        FileInputStream fis = null;
        BufferedWriter bw = null;

        try {
            fis = new FileInputStream(fi.getDuongdan());
            bw = new BufferedWriter(new FileWriter("torrent/" + fi.getTenfile() + ".torrent"));
            bw.write(fi.getSochunk() + "\r\n");
            bw.flush();
            LogFile.Write("So luong chunk: " + fi.getSochunk());
            
            
            // if we have no listeners, do nothing...
            if (listeners != null && !listeners.isEmpty()) {
                // make a copy of the listener list in case
                //   anyone adds/removes listeners
                Vector targets;
                synchronized (this) {
                    targets = (Vector) listeners.clone();
                }
                // create the event object to send
                CustomEventObject event = new CustomEventObject(0, fi.getSochunk());
                
                for (int i = 0; i < fi.getSochunk(); i++) {
                    byte[] buffer = new byte[(int) fi.getKichThuocChunk()];
                    int readsize = fis.read(buffer);
                    byte[] newbuffer = new byte[readsize];

                    System.arraycopy(buffer, 0, newbuffer, 0, readsize);
                    fi.ghichunk(i + 1, newbuffer);
                    String hash = fi.getHashCode(ThongTinChunk.duongDanChunk + fi.getTenfile() + "/" + fi.getTenfile() + "_" + (i + 1) + ".chunk");

                    bw.write((i + 1) + " " + hash + "\r\n");
                    bw.flush();
                    LogFile.Write("Cat chunk #" + i + ": " + hash);
                    
                    event._value = i + 1;
                    
                    //Phát sinh sự kiện đang cắt tập tin
                    Enumeration e = targets.elements();
                    while (e.hasMoreElements()) {
                        CustomEventListener l = (CustomEventListener) e.nextElement();
                        l.onOccur(event);
                    }
                }

                //Phát sinh sự kiện cắt tập tin hoàn tất
                Enumeration e = targets.elements();
                while (e.hasMoreElements()) {
                    CustomEventListener l = (CustomEventListener) e.nextElement();
                    l.onFinish(event);
                }
                LogFile.Write("Cat thanh cong " + fi.getSochunk() + "/" + fi.getSochunk() + " chunks");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(new JPanel(), "Lỗi:\n\n" + ex.getMessage());
            LogFile.Write("!ERROR: " + ex.getMessage());
        } finally {
            try {
                bw.flush();
                bw.close();
                fis.close();
            } catch (IOException ex) {
                Logger.getLogger(ThreadCatFile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        LogFile.Write("#END Catfile()");
    }