-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy.java
More file actions
59 lines (53 loc) · 1.86 KB
/
Copy pathcopy.java
File metadata and controls
59 lines (53 loc) · 1.86 KB
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.tdsi;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JFileChooser;
/**
*
* @author ouz
*/
public class Copy {
static File src;
static File dst;
static void copier() throws FileNotFoundException, IOException {
//creation de Filechooser
JFileChooser jfc=new JFileChooser();
//définir le titre de la fenetre
jfc.setDialogTitle("choisir un fichier");
//on ouvrela fenetre, val contient 0 s'il clique sur ouvrir
int val=jfc.showOpenDialog(jfc);
//s'il ne clique pas sur ourvrir on ferme le projet
if(val!=JFileChooser.APPROVE_OPTION)
System.exit(1);
//on choisi le File qu'il a choisi
src=jfc.getSelectedFile();
//on crée un flux de lecture du fichier source
FileInputStream fis =new FileInputStream(src);
//on crée le fichier de destination dans le projet
dst=new File("copie_"+jfc.getName(src));
//on crée un flux d'ecriture sur dst
FileOutputStream fos=new FileOutputStream(dst);
//Bufferization des deux flux
BufferedInputStream bis=new BufferedInputStream(fis);
BufferedOutputStream bos=new BufferedOutputStream(fos);
//on déclare le table de byte
byte [] buff= new byte[1024];
//la taille des bytes lus
int len;
while((len=bis.read(buff))!=-1){
bos.write(buff,0,len);
}
bis.close();
bos.close();
}
}