title: How to read a .dat file and write to a text file?
body: <p>How to read a .dat file in Java and write that data to a text file.
  This is my code which i have tried but i am getting error. Please someone help me.</p>
  
  <p>String inputFile = "file.dat";</p>
  
  <pre><code>FileInputStream(inputFile));    
  DataInputStream in = new DataInputStream (new FileInputStream(inputFile));
  while (in.available() &gt;0) {
  String temp = in.readUTF();
     System.out.println(temp);
  }
  </code></pre>
  
  <hr>
  
  <h2>error--</h2>
  
  <p>Exception in thread "main" java.io.UTFDataFormatException: malformed input
  around byte 3</p>
  
  <pre><code>at java.io.DataInputStream.readUTF(Unknown Source)
  at java.io.DataInputStream.readUTF(Unknown Source)
  at datReader.main(datReader.java:16)
  </code></pre>