externalizar strings java

0

Let's see if someone can give me a cable.

I have a huge java project and I would like to know if there is any way to outsource all String to constants of all *. java files

(Eclipse) Source - Externalize string only does it in a file and going one by one is unfeasible. Any ideas?

Thanks in advance.

    
asked by Jose Luis 18.11.2017 в 03:13
source

1 answer

0

You could use a .properties file

I'll attach an example ...

import java.io.InputStream;
import java.util.Properties;

public class TestPropeties {

    public static void main(String[] args) {
    Properties prop = new Properties();
    String resourceName = "archivo.properties";
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    try {
        InputStream resourceStream = loader.getResourceAsStream(resourceName);
        prop.load(resourceStream);
    } catch (Exception e) {
        System.out.println("Ocurrió un error al cargar el archivo de propiedades");
    }
    System.out.println(prop.getProperty("clave"));
    }
}

Where file.properties has the information in this way

clave=valor
clave2=valor2

That properties file can be opened from any class you require.

    
answered by 18.11.2017 в 23:43