1

I am trying to write Persian text to a .txt file in Java. Because Persian (Farsi) is read from right to left, how can I write each line such that it is right aligned?

I am currently using Apache's FileUtils.writeLines(), but I am open to other alternatives in order to achieve the problem.

Thanks!

littleK
  • 17,803
  • 26
  • 116
  • 179

3 Answers3

0

You can wrap each line into a String.format

String.format("%s", formatter.format(i))

or Apache StringUtils has several methods: leftPad, rightPad, center and repeat.

Read following thread. How can I pad a String in Java?

Community
  • 1
  • 1
Surinder ツ
  • 1,696
  • 3
  • 16
  • 26
0

You just add spaces if you want to have lines with specific size, otherwise it depends on the tool you use for reading it.

sbiz
  • 301
  • 3
  • 10
0

Text alignment is determined by UI that would show your text file. If you are using a plain text file, so it does not have facilities to tell it its text alignment.

If you insist on it, there are special Unicode characters that can tell UI it must be interpreted as right-to-left text. Please see here.

Afshar Mohebi
  • 8,242
  • 12
  • 72
  • 116