I was working on a property file. On it, I have an key which is "user_email" and the value, I set it to toomeuser0@gmail.com.
Now, in my code, I want the email value to iterate whenever my program runs, so toomeuser0@gmail.com will be toomeuser1@gmail.com and so on and from there, I read the email value in the property file and call it in my program.
public String getEmailFromProperty(){
String new_email = "";
try{
new ConfigReader();
FileOutputStream fos = new FileOutputStream(property_file);
StringBuilder str = new StringBuilder(property.getProperty("user_email"));
char charWithNumber = str.charAt(9); // get the number character of the email (starts with 0)
int toInteger = (int) charWithNumber; // convert that character number to an Integer value
int numericValue = Character.getNumericValue(toInteger+1); // the number character in email is converted to int then incremented by 1 on each run
int toAscii = numericValue + 48; // the number character (which is now an Int) is added by 48
char toChar = (char) toAscii; // it is converted back to a character in order for it to be passed as a parameter to setCharAt() method
str.setCharAt(9, toChar); // attached the newly incremented number character to the email @ 9th index
new_email = str.toString(); // converted the StringBuilder variable str to an ordinary String in order to call toString() method
property.setProperty("user_email", new_email); // now, I wrote the new email to the property file using the "user_email" key
property.store(fos, null);
fos.close();
}
catch(Exception e){
System.out.println("Error is " + e.getMessage());
}
return new_email;
}
I know this is kinda messy for you. But when the email number character reaches to value 9 and then it increments, I expected it to be 10. However, it returns '/' character. What I want after the run is toomeuser10@gmail.com NOT toomeuser/@gmail.com