tp6
This commit is contained in:
48
DEV3.2/TP06/02_Couleurs/LectureFichier.java
Normal file
48
DEV3.2/TP06/02_Couleurs/LectureFichier.java
Normal file
@@ -0,0 +1,48 @@
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.awt.*;
|
||||
|
||||
public class LectureFichier {
|
||||
|
||||
private Map<String, Color> dictCouleurs;
|
||||
|
||||
public LectureFichier() {
|
||||
this.dictCouleurs = new HashMap<>();
|
||||
|
||||
try {
|
||||
BufferedReader lecture = new BufferedReader(new FileReader("rgb.txt"));
|
||||
|
||||
try {
|
||||
String ligne = lecture.readLine();
|
||||
while(ligne != null) {
|
||||
String r = ligne.substring(0, 3).trim();
|
||||
String g = ligne.substring(4, 7).trim();
|
||||
String b = ligne.substring(8, 11).trim();
|
||||
|
||||
String nomCouleur = ligne.substring(11).strip();
|
||||
|
||||
this.dictCouleurs.put(nomCouleur, new Color(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b)));
|
||||
|
||||
ligne = lecture.readLine();
|
||||
|
||||
|
||||
}
|
||||
} catch(IOException e) {
|
||||
System.err.println("Erreur de lecture dans rgb.txt !");
|
||||
}
|
||||
try {
|
||||
lecture.close();
|
||||
} catch(IOException e) {
|
||||
System.err.println("Erreur de fermeture de rgb.txt !");
|
||||
}
|
||||
} catch(FileNotFoundException e) {
|
||||
System.err.println("Erreur d'ouverture de rgb.txt !");
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Color> getDictCouleurs() {
|
||||
return this.dictCouleurs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user