I have to left pad 0's while printing it on console. Here I am reading number from a file.. The code is as below:
public class FormatNumber {
public static void main(String[] args) {
Properties properties=new Properties();
File newFile=new File("FormatNo.properties");
try {
newFile.createNewFile();
properties.load(new FileInputStream(newFile));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String transId = properties.getProperty("TransNum");
System.out.println(transId);
String RegisId = properties.getProperty("RegId");
String R= String.format("%02d", RegisId);
System.out.println(R);
String T=String.format("%04d", transId);
System.out.println(T); }
In FormatNo.properties file I am storing TransNum=6 and RegId=56. The error what I am getting is
Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.String