title: Writing a Method to a text file
body: <p>The methods within the my code produce the correct output. However, I'm having trouble taking the output from my methods and writing it out to a textfile. Is there some special function i need to use to accomplish this?</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  
  class First {
  
      public static ArrayList BestRouteArray(int[] someintlist) {                   //Sorting method to turn int list into array
          ArrayList&lt;Integer&gt; BestRouteArray = new ArrayList&lt;Integer&gt;();
          for (int index = 0; index &lt; someintlist.length; index++) {
              BestRouteArray.add(someintlist[index]);
          }
          return BestRouteArray;
      }
  
  
      public static void MostEfficientRoute(ArrayList&lt;Integer&gt; array) {
  
          ArrayList&lt;Integer&gt; hotel = array;
          int[] BestRoute = new int[hotel.size()];                                    //Defining Variables
          int[] Stop = new int[hotel.size()];
  
          for (int i = 0; i &lt; hotel.size(); i++)
          {
              BestRoute[i] = (int) (Math.pow((200 - hotel.get(i)), 2));               //Penalty Calculations
              Stop[i] = 0;                                                            //Stop, to index values
              for (int j = 0; j &lt; i; j++)
              {
                  if (BestRoute[j] + Math.pow((200 - (hotel.get(i) - hotel.get(j))), 2) &lt; BestRoute[i])
                  {
                      BestRoute[i] = (int) (BestRoute[j] + Math.pow((200 - (hotel.get(i) - hotel.get(j))), 2));
                      Stop[i] = j + 1;
                  }
  
              }
  
          }
  
          // Printing values
          ArrayList&lt;Integer&gt; Storage = new ArrayList&lt;&gt;();
          int index = Stop.length-1;
          while(index&gt;=0)
          {
              Storage.add((index + 1));                                    //Loop to get index of Hotel and Penalty Values
              index = Stop[index]-1;
  
          }
          Collections.reverse(Storage);                                    //Reversing order of Storage
          ArrayList&lt;Integer&gt; StoredValues = BestRouteArray(BestRoute);        //Taking values from best path int list and storing in array list
          if(StoredValues.get(0) != 0){
              StoredValues.add(0, 0);
          }
          ArrayList&lt;Integer&gt; Penalty = new ArrayList&lt;&gt;();
          ArrayList&lt;Integer&gt; HotelMarker = new ArrayList&lt;&gt;();             //Initializing Penalty, and hotel maker as arraylist
          ArrayList&lt;Integer&gt; StorageHotel = Storage;                      //Storing Storage values in Storage hotel values to manipulate
  
          for(int i = 0; i &lt; Storage.size(); i++)                         //Using the storage values as an index to pull Penalty values from
          {
              Penalty.add(StoredValues.get(Storage.get(i)));
          }
          for(int i = 0; i &lt; Storage.size(); i++)                         //Creating new array list to hold storage values -1
          {
              int value = StorageHotel.get(i);
              StorageHotel.set(i, (value - 1));
          }
          for(int i = 0; i &lt; Storage.size(); i++)                         //Using the new StorageHotel list as index to pull hotel values from
          {
              HotelMarker.add(hotel.get(StorageHotel.get(i)));
          }
          for(int i = 0; i &lt; Storage.size(); i++) {                       //Printing the Values for both Markers and Penalty
              System.out.print("Distance: " + HotelMarker.get(i) + " ");
              System.out.println("Total Penalty: " + Penalty.get(i) + " ");
          }
  
      }
  
  
      public static void main(String[] args) throws FileNotFoundException, java.io.IOException {
  
          Scanner dataFile = new Scanner(new File("C:\\Users\\USER\\Documents\\Data.txt"));
          ArrayList&lt;Integer&gt; hotels = new ArrayList&lt;&gt;();
          hotels.add(0);
          while (dataFile.hasNextLine()) {
              hotels.add(dataFile.nextInt());
          }
          dataFile.close();
          MostEfficientRoute(hotels);
  
  
          PrintWriter outputFile = new PrintWriter(new FileWriter("C:\\Users\\USER\\Documents\\OutputData.txt", true));
          outputFile.append(MostEfficientRoute(hotels));
          outputFile.append("account1 balance: ");
          outputFile.close();
      }
          }
  </code></pre>