title: How to read a file, reverse the order, and write reverse order
body: <p>Like a similar project I made, this project is reading characters from a txt file, reversing the order of the string and rewriting it to another txt file. But it keeps outputting my exception of "Something went wrong". Can anyone help me fix what is going wrong?</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Scanner;
  
  public class ReverseFile
  {
      public static void main(String[] args) throws IOException
         {
            try{
            String source = args[0];
            String target = args[1];
  
            File sourceFile=new File(source);
  
            Scanner content=new Scanner(sourceFile);
            PrintWriter pwriter =new PrintWriter(target);
  
            while(content.hasNextLine())
            {
               String s=content.nextLine();
               StringBuffer buffer = new StringBuffer(s);
               buffer=buffer.reverse();
               String rs=buffer.toString();
               pwriter.println(rs);
            }
            content.close();    
            pwriter.close();
            System.out.println("File is copied successful!");
            }
  
            catch(Exception e){
                System.out.println("Something went wrong");
            }
         }
  }
  </code></pre>
  
  <p>So here is the information from the stacktrace:</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 0
      at ReverseFile.main(ReverseFile.java:36)
  </code></pre>