Reputation: 455
I'm trying to write two strings to a file:
var str1 = "this is" var str2 = "a good day"
such that str1 should be written right justified and str2 left justified.
I read that it works something like this:
fw.write("%" + str1)
fw.write("%-" + str2)
But, it's not giving me the expected result. Why is that?
EDIT:
val fw = new FileWriter("results.txt", true) ;
Upvotes: 0
Views: 1901
Reputation: 5202
"+" only concatenates two strings. Try format method.
fw.write("%-10s".format(str2))
Upvotes: 1