zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package PbuliClass;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;
 
/**ÎļþÏÂÔØÀàÓÃÓÚÏÂÔØÒ»¸öÒѾ­´æÔÚµÄÎļþ*/
public class DownloadFile {
    File file=null;
    File outfile=null;
    JFileChooser chooser;
    FileNameExtensionFilter filter;//Îļþ¹ýÂËÆ÷
    FileOutputStream out=null;//ÎļþÊä³öÁ÷
    FileInputStream in= null;//ÎļþÊäÈëÁ÷
    String filePath=null;
    String fileName=null;//±£´æµÄÎļþÃû³Æ
    public DownloadFile() {//¹¹Ôì·½·¨    
    
    }
    
    public String getFilePath() {
        return filePath;
    }
 
    /**ÉèÖÃÔ´ÎļþµÄ·¾¶*/
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
    
    public String getFileName() {
        return fileName;
    }
 
    /**ÉèÖñ£´æÎļþµÄÃû³Æ*/
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    
    /**ÏÂÔØÈËÔ±ÐÅÏ¢±í·½·¨*/
    public void dowPersonFile(JPanel jpan) {
        setFilePath("systemFiles/sourse/ÈËÔ±ÐÅÏ¢±í.xls");
        setFileName("ÈËÔ±ÐÅÏ¢±í.xls");
        DownloadFilein(jpan);        
        
    }
    
    /**ÏÂÔØ»ùÕ¾µ¼ÈëÄ£°å·½·¨*/
    public void downAnchorFile(JPanel jpan) {
        setFilePath("systemFiles/sourse/»ùÕ¾µ¼ÈëÄ£°å.xls");
        setFileName("»ùÕ¾µ¼ÈëÄ£°å.xls");
        DownloadFilein(jpan);        
        
    }
    
    /**ÏÂÔØ±êÇ©IDµ¼ÈëÄ£°å·½·¨*/
    public void downTagIdFile(JPanel jpan) {
        setFilePath("systemFiles/sourse/±êÇ©IDµ¼ÈëÄ£°å.xls");
        setFileName("±êÇ©IDµ¼ÈëÄ£°å.xls");
        DownloadFilein(jpan);        
        
    }
    
    /**ÏÂÔØÎļþµÄ·½·¨*/
    public void DownloadFilein(JPanel jpan){
        chooser = new JFileChooser();
        file=new File(getFilePath());                
        int option = chooser.showSaveDialog(jpan);// Èç¹ûÈ·¶¨Ôò·µ»Ø0£¬È¡Ïû»ò¹Ø±Õ·µ»Ø1                
        if (option == JFileChooser.APPROVE_OPTION){            
            String outName=chooser.getSelectedFile().getAbsolutePath()+getFileName();//µ¼³öµÄÎļþÃû×ÖĬÈÏΪexcelÎļþ
            outfile=new File(outName);
            try {
                in=new FileInputStream(file);
                out=new FileOutputStream(outfile);
                int len;
                try {
                    len = in.read();
                    while (len!=(-1))
                    {
                        out.write(len);
                        len = in.read();
                    }
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                
                try {
                    out.flush();//Çå¿Õ»º´æ
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }finally{
                if(in !=null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(out !=null) {                    
                    try {
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                
            }
            ShowMessage.zidingyi(outName+"ÏÂÔØ³É¹¦£¡");
        }
    }
 
 
}