1. try{
  2. FileInputStream fstream = new FileInputStream(filename);
  3. // Get the object of DataInputStream
  4. DataInputStream in = new DataInputStream(fstream);
  5. BufferedReader br = new BufferedReader(new InputStreamReader(in));
  6.  
  7. DataOutputStream ut = new DataOutputStream(new FileOutputStream(f));
  8. String strLine;
  9. //Read File Line By Line
  10. while ((strLine = br.readLine()) != null) {
  11. // Print the content on the console
  12.  
  13. ut.writeUTF(strLine+"\n");
  14.  
  15. }
  16. //Close the input stream
  17. in.close();
  18. }catch (Exception e){//Catch exception if any
  19. System.err.println("Error: " + e.getMessage());
  20. }