how to write to java file in the best way?

To write the contents of ResultSet into a file, is there a better way?

  • I want to write the contents of the ResultSet to a CSV file. I have used the following code to for the same: query="select * from client where client name= "+custName; st=con.prepareStatement(query); rs=st.executeQuery(query); System.out.println(query); while(rs.next()) { int colNo=rs.getMetaData().getColumnCount(); //System.out.println("Enter the name of the file:"); //String name=bufIn.readLine(); File f=new File(fname); FileWriter fstream = new FileWriter(f); bufferedWriter = new BufferedWriter(fstream); for(int i=1;i<(colNo+1);i++) { bufferedWriter.append(rs.getMetaData().g… System.out.println(rs.getMetaData().getC… if(i<colNo) { bufferedWriter.append(","); } else { bufferedWriter.append("\r\n"); } } **************************************… I have used buffered writer to write the file as you can see above. Please tell me if using buffered writer the best way to write in a CSV file. I want to use a very efficient IO code, since this code gets deployed on server. Plz help. To write the contents of ResultSet into a file, is there any oter better way?

  • Answer:

    use PrintWriter with which you can use print, println methods.

Asghar at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.