The below is the code that I tried to print the output that comes on the console to a text file. The main idea of the code is fetch values from a csv file and print the output to a text file. Could someone let me know how this can be achieved.
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.csvreader.CsvReader;
public class projectInfo {
public static void main(String[] args) {
StringBuffer buffer = new StringBuffer();
Connection conn;
int count = 0;
String sampleIddisp = null;
String sample_name = null;
String compound_name = null;
String registration_date = null;
}
products.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("\n Total number of records processed:" + count);
}
}
}
You never place any content in your
StringBufferbuffer, so it is empty when you write it to file:buffercould potentially consume a large amount of memory here.A better approach to writing the data to file would be to write the data as you read it from the database: