title: Write int to file using DataOutputStream
body: <p>I'm generating random ints and trying to write them down to a file. The problem is when I open the file I've created I don't find my ints but a set of symbols like squares etc... Is it a problem of encoding ?</p>
  
  <pre><code>import java.io.DataOutputStream;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  public class GenerateBigList {
  
      public static void main(String[] args) {
          //generate in memory big list of numbers in  [0, 100]
          List list = new ArrayList&lt;Integer&gt;(1000);
          for (int i = 0; i &lt; 1000; i++) {
              Double randDouble = Math.random() * 100;
              int randInt = randDouble.intValue();
              list.add(randInt);
          }
  
          //write it down to disk
          File file = new File("tmpFileSort.txt");
          try {
  
              FileOutputStream fos = new FileOutputStream("C:/tmp/tmpFileSort.txt");
              DataOutputStream dos = new DataOutputStream(fos);
              writeListInteger(list, dos);
              dos.close();    
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      private static void writeListInteger(List&lt;Integer&gt; list, DataOutputStream dos) throws IOException {
          for (Integer elt : list) {
              dos.writeInt(elt);
          }
      }
  
  }
  </code></pre>
  
  <p>A partial copy paste from the created file:</p>
  
  <pre><code>/   O   a   C   ?       6   N       
  </code></pre>