title: Java Line IO vs C++ IO?
body: <p>Note that this is NOT a "better-than" discussion.</p>
  
  <p>I'm a C++ programmer, and it makes me feel incredibly dumb not to know how to do very much Java file IO.</p>
  
  <p>I need to store a number of different data types in a file to be read back later.  These include integers and Strings of variable length.</p>
  
  <p>In C++, I could just use:</p>
  
  <pre><code>//wont actually know the value of this
  string mystr("randomvalue");
  //the answer to the Ultimate Question of Life, the Universe, and Everything
  int some_integer = 42;
  
  //output stream
  ofstream myout("foo.txt");
  //write the values
  myout &lt;&lt; mystr &lt;&lt; endl;
  myout &lt;&lt; some_integer &lt;&lt; endl;
  
  //read back
  string read_string;
  int    read_integer;
  
  //input stream
  ifstream myin("foo.txt");
  //read back values
  //how to do accomplish something like this in Java?
  myin &gt;&gt; read_string;
  myin &gt;&gt; read_integer;
  </code></pre>
  
  <p>Thanks very much!</p>