title: Writing an ORACLE BLOB file in java
body: <p>I uploaded a html file from my D drive to an ORACLE database, now i am trying to retrieve the same file to another drive in my pc with a new name but i am not able to receive the exact same file, The code that i have used is listed below.
  My question is how do i get the same copy of the file that i stored in my database.    </p>
  
  <pre><code>import java.io.FileWriter;
  
  import java.io.FileWriter;
  import java.io.InputStream;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  
  public class RBLOB {
  public static void main(String args[])throws Exception
  {
  try(Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");)
  {
  PreparedStatement ps=con.prepareStatement("select * from players");
  ResultSet rs=ps.executeQuery();
  rs.next();
  InputStream is= rs.getBinaryStream(2);
  
  FileWriter fw=new FileWriter("C:\\Users\\y_san\\Desktop\\test.html");
  while(is.read()!=-1)
  {
    fw.write(is.read());
   System.out.println(is.read());
   fw.flush();
  }
  }
  catch(Exception ex)
  {
  System.out.println(ex.getMessage());
  }
  }
  }
  </code></pre>