Reputation: 1111
for(i=0;i<20;i++)
bufferedwriter.write("c"+i+"\t"+"p"+i+"\t")
After printing 6th iteration 7th one is again printed from starting left of the page from newline. How to avoid this?
Upvotes: 1
Views: 142
Reputation: 418147
BufferedWriter.write()
does not arbitrarily start new lines.
It is just your file viewer/editor that wraps the lines if they are too long and they don't fit into one line. Another case could be if the objects which you concatenate (or their String
representation) contains new line characters but this not apply to you in your case.
So your code is just fine. However note that you can achieve finer and more precise column alignment by using a format string:
String s = String.format("%5d", i) // Number with 5 width, aligned right
String s = String.format("%5s", "hi") // String with 5 width, aligned right
Upvotes: 1