Bonjour tout le monde,
Afin d'éviter d'écrire en "dur" du texte dans mon code, je passe par un fichier .properties.
J'ai donc créé une classe permettant d'aller lire ce fichier et me renvoyer la valeur en fonction de la clef donnée en paramètre.
J'ai dans un premier temps mis le chemin absolu qui marche à merveille cependant, je préfère passer par un chemin relatif.
Voici le code:
J'ai laissé en commentaire la ligne avec le chemin absolu qui fonctionne.
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 public class ReadProperties { public static String getPropertyValue(String key){ Properties properties = new Properties(); InputStream input = null; try { // input = new FileInputStream("d:/Profiles/mra/workspaceRCP/eclipsercp.editeurxml.menubarre/src/main/resources/config/ApplicationResources.properties"); input = new FileInputStream(ReadProperties.class.getResource("/config/ApplicationResources.properties").getFile()); properties.load(input); } catch (IOException e) { e.printStackTrace(); } String value = properties.getProperty(key); return value; } }
La seconde ligne (input = ...) ne me génère pas d'erreur de compilation mais quand je lance le programme j'ai une erreur:
java.io.FileNotFoundException: \config\ApplicationResources.properties (Le chemin d’accès spécifié est introuvable)
Voici l'arborescence de mon projet:
Je ne vois pas où est l'erreur car j'ai reproduis un bout de code que j'utilise sur une ihm et qui fonctionne très bien:
Quelqu'un à t-il une idée?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 ImageIcon logo = new ImageIcon(new ImageIcon(InterfaceDeLancement.class.getResource("/images/logo.jpg")) .getImage() .getScaledInstance(64, 36, Image.SCALE_DEFAULT));
Merci d'avance.
Cordialement,
Partager