how can i reverse a string ,from a file, CHARACTER by CHARACTER and output it in another file?

2008-07-22 9:34 am
How will I write a class which will read the contents of a text file. The program must then output the same text into a JOptionPane window and at the same time output the same text into another file. The output text must be in reverse order. For example, if the first file contains the following texts:

Harry Potter
Hogwarts School of Witchcraft and Wizardry
London, England

The output (JOptionPane and output to the second file) must be:

dnalgnE, nodnoL
yrdraziW dna tfarchctiW fo loohcS strawgoH
rettoP yrraH

...thanks for those who will answer...

...i'll appreciate more if you can explain it for me and for those who have the same questions like mine...

回答 (1)

2008-07-22 10:10 am
✔ 最佳答案
If the file isn't that big (let's say if it has a few hundred characters), I'd suggest putting all the contents into a StringBuffer first and then using the StringBuffer.reverse() method to handle it. If the file you're going to reverse is a few hundred megabytes in size, then you'd better do the reverse on a lower level (probably on file input stream level). But then you'll have to do your own calculations if the contents contain multibyte characters.


收錄日期: 2021-05-01 01:04:22
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080722013443AAotTjU

檢視 Wayback Machine 備份