Bonjour,
J'ai un problème au niveau d'une de mes méthodes et je n'arrive pas à trouver la solution. Pouvez vous me guider?
Je m'explique :
j'ai un fichier texte ci dessous :
son xml associé :#!/bin/csh -xv
#BSUB -J calmod_POGO_2CU fichie.txt
#BSUB -o calmod_POGO_2CU.o%J
#BSUB -L /bin/csh
#>
set dir_listing = {dir_listing}
set toto = {toto}
set k = $jhgjgh + {k}
set d = $toto + {d}
set nono = {nono}
set c = {c} + $toto
set a = {a}
#<
umask 002
#----------------------------------------------------------------------
jnfjkg
$gdfgdfg
dfgdfgdfg74654654fdg
fdgdfg
fgdf
fgfg
fg;hmfh
dfdsfgdfg
set khjkhjkhkj 8787687657
titi
set b
set e
Code xml : 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 <?xml version="1.0" encoding="utf-8"?> <parametters> <value name = "dir_listing"> jdfgjkdfnbjkdfnbjnfdbndfjbndfbndfkb </value> <value name = "toto"> tata </value> <value name = "k"> kop </value> <value name = "d"> 9 </value> <value name = "nono"> ueueue777 </value> <value name = "c"> 7 </value> <value name = "a"> titi </value> </parametters>
et mes méthodes :
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 /** * affiche le nouveaux texte entier modifié ( la partie entre ZONE_B et ZONE_E modifiée : keys => values) * @param ZONE_B * @param ZONE_E * @param cl * @param texteRef * @param filename * @return */ public String recupValues( String ZONE_B, String ZONE_E, Classement cl , String filename, String texteRef, String VALUE_B, String VALUE_E ){ Finally fp = new Finally(); String c = fp.valeursKeys(VALUE_B, VALUE_E, cl, texteRef); c = ZONE_B.concat(c).concat(ZONE_E); // lecture fichier CSH StringBuilder texte = new StringBuilder(); try{ BufferedReader buff = new BufferedReader(new FileReader(filename)); try { String line; while ((line = buff.readLine()) != null) { texte.append(line+"\n" ); } } finally { buff.close(); } } catch (IOException ioe) { System.out.println("Erreur --" + ioe.toString()); } //System.out.println(texte.toString()); String fullText = texte.toString(); System.out.println(fullText); String motif = "(?s)symbole1.*?symbole2"; // ex : symbole1 = #> ; symbole2 = #< motif = motif.replaceFirst("symbole1", ZONE_B); motif = motif.replaceFirst("symbole2", ZONE_E); fullText = fullText.replaceFirst(motif, c); return fullText; }
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 /** * Lit le fichier spécifié et extrait la partie située entre ZONE_B et ZONE_E * @param filename nom du fichier * @return la chaîne extraite ou null si aucune chaîne trouvée, ou si le fichier n'existe pas */ public String extract(String filename, String ZONE_B, String ZONE_E) { try { StringBuilder stringBuilder = new StringBuilder(); BufferedReader buff = new BufferedReader(new FileReader(filename)); try { String line; while ((line = buff.readLine()) != null) { stringBuilder.append(line); stringBuilder.append('\n'); } } finally { buff.close(); } String toutLeFichier = stringBuilder.toString(); int a = toutLeFichier.indexOf(ZONE_B); int b = toutLeFichier.indexOf(ZONE_E); if (a >= 0 && b >= 0) { return toutLeFichier.substring(a + ZONE_B.length(), b); } } catch( FileNotFoundException e) { System.err.println("Fichier " + new File(filename).getAbsolutePath() + " introuvable"); } catch (IOException ioe) { System.err.println("Erreur --" + ioe.getMessage()); ioe.printStackTrace(); } return null; }
le problème c'est que quand je lance mon main :
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 import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; public class Tests { public static void main(String[] args) { String filePath = "C:\\Users\\ksmaili\\workspace\\fichiertraitable.txt"; Finally fn = new Finally(); String ZONE_B = "#>"; String ZONE_E = "#<"; String VALUE_B = "{"; String VALUE_E = "}"; Classement cl = new Classement(); /*String texteRef = "set dir_listing = {dir_listing}" + "set toto = {toto}" + "set k = $jhgjgh + {k}"+ "set d = $toto + {d}" + "set nono = {nono}" + "set c = {c} + $toto" + "set a = {a}" ; */ // lire filezPath : try{ BufferedReader buff = new BufferedReader(new FileReader(filePath)); try { String line; while ((line = buff.readLine()) != null) { //System.out.println(line); } } finally { buff.close(); } } catch (IOException ioe) { System.out.println("Erreur --" + ioe.toString()); } String p = fn.extract(filePath, ZONE_B, ZONE_E); System.out.println(p); String h = fn.recupValues(ZONE_B, ZONE_E, cl, filePath, p, VALUE_B, VALUE_E); //System.out.println(h); } }
J'ai cette erreur là qui s'affiche :
Avez vous une idée ?Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Unknown Source)
at java.util.regex.Matcher.replaceFirst(Unknown Source)
at java.lang.String.replaceFirst(Unknown Source)
at Finally.recupValues(Finally.java:249)
at Tests.main(Tests.java:48)
Partager