So even though this is a simple project, I found a lack of good code on the web under this topic for multi lined strings. I thought I would share it with everyone. Hope it helps you! Prints file foward first, then in reverse (and yes there are many different ways to do this i.e. stringbuffer)

Please give feedback as to what you think...Thanks guys!

package reverseorama;

/**
 *
 * @author Jamesonh20
 * @version 9/17/10
 */
import javax.swing.*;
import java.io.*;
import java.util.*;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        FileReader myReader;
        JFileChooser myChooser = new JFileChooser();
        if(myChooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION){
            File myFile = myChooser.getSelectedFile();
            try{
                myReader = new FileReader(myFile);
                Scanner myScanner = new Scanner(myReader);
                
                while (myScanner.hasNextLine()){
                    String textLine = myScanner.nextLine();
                    System.out.println(textLine);
                }                
                myReader.close();
                
                myReader = new FileReader(myFile);
                 myScanner = new Scanner(myReader);
                
                while (myScanner.hasNextLine()){
                    String textLine = myScanner.nextLine();                    
                    for(int i=textLine.length()-1; i>=0; i--)
                    {
                       System.out.print(textLine.charAt(i));
                    }
                    System.out.println();
                }                
                myReader.close();
            }
            catch (FileNotFoundException myEx) {
                System.out.println();
            }
            catch (IOException myEx){
                System.out.println(myEx.getMessage());
            }
        }
    }

}

If you are going to provide code to be used as a learning tool it needs to be commented well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.