title: Java wrong output file (encoding)
body: <p>I have some void functions that prints out to console. However, I had to write them to text file and that is why, I used</p>
  
  <pre><code>PrintStream out = new PrintStream(newFileOutputStream("Programoutput.txt"));
  System.setOut(out);
  </code></pre>
  
  <p>in the beginning of my main function. However the output file after running the program contains some Chinese characters. Any idea why this happened? You can find my code below. I am using Ubuntu 16.04 (maybe affects).</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      path = args[0];
      PrintStream out = new PrintStream(new FileOutputStream("Programoutput.txt"));
      System.setOut(out);
      long startTime = System.nanoTime();
      // Set up Commands to Array
      String[] commands = new String[numOfLines(path)];
      setUpArray(path, commands);
      // Build Memory
      int memorySize = Integer.parseInt(commands[0].split(" ")[1]);
      String replacement = commands[1].split(" ")[1];
      String searchStructure = commands[2].split(" ")[1];
      // Creating Data Structure Objects
      Queue memory = new Queue(memorySize);
      BST binaryTree = new BST();
      ModifiedQueue mq = new ModifiedQueue(memorySize);
      MaxHeapTree hTree = new MaxHeapTree(memorySize);
      if(replacement.equals("FIFO") &amp;&amp; searchStructure.equals("BinarySearch")){
          fifoQueue(memory, binaryTree, commands);
      }else if(replacement.equals("PriorityQueue") &amp;&amp; searchStructure.equals("BinarySearch")){
          priorityQueue(hTree, binaryTree, commands);
      }else if(replacement.equals("SecondChance") &amp;&amp; searchStructure.equals("BinarySearch")){
          secondChanceQueue(mq, binaryTree, commands);
      }
      long endTime = System.nanoTime() - startTime;
      double totalTime = endTime/1e9;
  
      System.out.println("Elapsed time in seconds: " + totalTime);  
  }
  </code></pre>