Files
DEV/DEV2.1/TP14/02_Couleurs/LectureFichier.java

50 lines
1.3 KiB
Java
Raw Normal View History

2025-03-31 17:29:54 +02:00
import java.awt.*;
import java.io.*;
2025-09-04 15:36:55 +02:00
import java.util.Arrays;
2025-03-31 17:29:54 +02:00
public class LectureFichier {
private Color[] tabCouleurs;
private String[] tabNomsCouleurs;
public LectureFichier() {
2025-09-04 15:36:55 +02:00
this.tabCouleurs = new Color[800];
this.tabNomsCouleurs = new String[800];
2025-03-31 17:29:54 +02:00
try {
BufferedReader lecture = new BufferedReader(new FileReader("rgb.txt"));
try {
String ligne = lecture.readLine();
2025-09-04 15:36:55 +02:00
int compteur = 0;
while (ligne != null) {
int r = Integer.parseInt(ligne.substring(0, 3).replaceAll(" ", "0"));
int g = Integer.parseInt(ligne.substring(4, 7).replaceAll(" ", "0"));
int b = Integer.parseInt(ligne.substring(8, 11).replaceAll(" ", "0"));
this.tabCouleurs[compteur] = new Color(r, g, b);
ligne = ligne.substring(11, ligne.length()).replaceAll(" ", "");
this.tabNomsCouleurs[compteur] = ligne;
ligne = lecture.readLine();
compteur++;
}
2025-03-31 17:29:54 +02:00
} catch (IOException e2) {
System.err.println("Erreur de lecture.");
}
try {
lecture.close();
} catch(IOException e3) {
System.err.println("Erreur de fermeture.");
}
} catch(IOException e) {
System.err.println("Erreur d'ouverture");
}
}
2025-09-04 15:36:55 +02:00
public Color[] getCouleurs() {
return this.tabCouleurs;
}
public String[] getNomsCouleurs() {
return this.tabNomsCouleurs;
}
2025-03-31 17:29:54 +02:00
}