My input text file is :-
kiShore,kUMar,bhAvanam
My output file must be:-
Kishore,Kumar,Reddy
Simply my code needs to capitalize the 1st letters in file and This is my code
public static void main(String[] args) throws Exception {
// write your code here
BufferedReader br = new BufferedReader(new FileReader("input.txt"));
FileWriter fw = new FileWriter("output.txt");
String line;
while ((line = br.readLine()) != null) {
String[] values = line.split(",");
for (String str : values) {
String msg = str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
br.mark(0);
if (br.read()!= -1)
{
msg=msg+",";
br.reset();
}
fw.write(msg);
}
}
fw.close();
br.close();
}
My code Works perfectly when file contains multiple lines like:
kIshore,kUMar
rEdDy
i get the exact output
Kishore,Kumar,Reddy
but if my Input file contains only a single line like:
kiShore,kUMar,bhAvanam
I get the output KishoreKumarBhavanam. I'm unable to insert commas in between words, if the input file contains only a single line
Expected result:
Kishore,kumar,Bhavanam
actual result:
KishoreKumarReddy