title: I need to read a .txt file from a java and write the sorted context to a different .txt file
body: <p>I have a I/O java file, a SDive file which contains main, a .txt Directory file that has random words in it and a Sorted .txt to return the random words in order ascending to descending. It print all the words in the Sorted but it is not sorted.</p>
  
  <pre><code>//Sort.java
  // required for input
  import java.io.FileReader;
  import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  // required for output
  import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  
  class Sort{
  
     private String[] tArr = new String[100];
  
         public void swap(int j) {      
  
            String temp = tArr[j-1];
            tArr[j-1] = tArr[j];
            tArr[j] = temp;
         }
  
        ///Bubble sort
        public void sort() {
           int n = tArr.length;
           for(int i = 0; i &lt; n; i++) {
              for(int j = 1; j &lt; n-i; j++) {
                 if(tArr[j-1].compareTo(tArr[j]) &gt; 0) {
                    swap(j);
                 }
              }
           }
        }
  
  public void read() {
  
      System.out.println("in read()");
      String pwd = System.getProperty("user.dir");
      String fileName = pwd + "/directory.txt";
      System.out.println("Looking for: " + fileName);
      String fileLine = "";
  
      try {
  
          File f = new File(fileName);
  
          if(f.exists()) { 
             System.out.println("Directory profile found, loading data...");
          }
          else {
             System.out.println("Directory profile not found, loading default...");
  
             return; // done, return back to the caller
          }
  
          // Read file
          FileReader data = new FileReader(fileName);
  
          // Wrap FileReader with BufferedReader
          BufferedReader br = new BufferedReader(data);
          //String tmp;
  
          int i=0;
          while ((fileLine = br.readLine()) != null) {                    
             tArr[i++] = fileLine;
          }
  
          // ok, time to load an existing profile
  
  
          // close the file
          br.close();
  
      } catch (FileNotFoundException fnf) {
          System.out.println("File not found: " + fileName);
      } catch (IOException ioe) {
          System.out.println("Error reading file: " + fileName);
      } catch (Exception exc) {
          System.out.println("Something went wrong: " + fileName);
      }
  
  }
  
      public void write() {
  
      System.out.println("in write()");
      String pwd = System.getProperty("user.dir");
      String fileName = pwd + "/Sorted.txt";        
  
      try {            
  
          System.out.println("Writing out to: " + fileName);
  
          File file = new File(fileName);
          // creates the file
          file.createNewFile();
          // create FileWriter object
          FileWriter writer = new FileWriter(file);
  
          // output to file
          // ADD pIdx, pArr, mood, and anything else here...
  
          for(int i = 0; i &lt; tArr.length; i++) {
              writer.write(tArr[i] + "\n");
          }            
  
          writer.flush();
          writer.close();
  
      } catch (IOException ex) {
          System.out.println("Error writing to file: " + fileName);
      }
  
    }
  
  }
  </code></pre>
  
  <p>And my main file is SDrive:</p>
  
  <pre><code> class SDriver{
  
      public static void main(String args []){
         Sort io = new Sort();
         io.read();
         io.write();
  
      }
  }
  </code></pre>