Closed DonkeyRit closed 1 year ago
Telegram API Bot API Key is a sensitive information which should be protected. The main intension of add configuration file is hiding api key from repository.
I've created a file named config.properties in resource folder with the following content
BOT_TOKEN = 8743b52063cd84097a65d1633f5c74f5
Then inside the function of a Java class you can use the following lines of code to read the config file.
String configFilePath = "src/config.properties";
FileInputStream propsInput = new FileInputStream(configFilePath);
Then we need to initialize java.util.Properties
and load the input file into the properties object.
Properties prop = new Properties();
prop.load(propsInput);
Now, we can read the configs from our file as follows,
System.out.println(prop.getProperty("BOT_TOKEN"));
Links:
Implement simple telegram bot: