Bonjour,
Est ce que qq peut m'aider s'il vous plaît, je suis débutante en java et j'ai crée un programme qui fait parser les fichiers.txt et qui générer a la sortir les fichier.txt, si j'ai 1000 fichier il vas génère 1000 a la sortie alors que je veux que 1 Seul fichier.txt ...
Merci en avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import java.io.*; import java.util.regex.*; public class parser { private static final String dir="MONITOR/"; // repertoire contenant les fichiers sources private static final String cible="cible/"; // repertoire contenant les fichiers cibles public static boolean Contient(String Ligne, String Mot) { Pattern p = Pattern.compile(".*"+Mot+".*"); Matcher m = p.matcher(Ligne); return m.matches(); } public static void parsing(String f){ try { FileOutputStream MyFile = new FileOutputStream(cible+"_NEW_"+(new File(f).getName())); BufferedReader b = new BufferedReader(new FileReader(f)); String c; while((c=b.readLine())!=null){ if (Contient(c, "gnx")) { MyFile.write((c+"\n").getBytes()); } } } catch (FileNotFoundException e1) { System.err.println("Fichier introuvable !"); e1.printStackTrace(); System.exit(-1); } catch (IOException e2) { System.err.println("Probleme de lecture !"); System.exit(-1); } } public static void main(String args []) { File cour = new File(dir); File[] fichs = cour.listFiles(); long x = System.currentTimeMillis(); for (int i=0; i<fichs.length;i++){ parsing(dir+fichs[i].getName()); } x = System.currentTimeMillis() - x; System.out.println("Temps de traitement: "+x+" ms"); } }
Partager