Taking lot of time when reading file and saving to txt as '|' seperated

I’m trying to read an excel file that’s more thank 500k rows and 100 columns
as below
try {
Workbook book = new Workbook(xlsxFile.getAbsolutePath());
long st = System.currentTimeMillis();
book.getWorksheets().forEach(sheet -> {
File f = new File(“C:\Users\Aspose\” + ((Worksheet) sheet).getName() + “.txt”);
LOGGER.info(" FILE ->"+f.getAbsolutePath());
LOGGER.info(" SHEET ->"+((Worksheet) sheet).getName());
OutputStream os;
try {
os = (OutputStream) new FileOutputStream(f);
String encoding = “UTF8”;
OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
BufferedWriter bw = new BufferedWriter(osw);
Cells cells = ((Worksheet) sheet).getCells();
for (int row = 1; row <= cells.getMaxDataRow(); row++) {
StringBuilder strb = new StringBuilder();
for (int col = 0; col <= cells.getMaxDataColumn(); col++) {
strb.append((cells.get(row, col)).getValue());
strb.append("|");
}
bw.write(strb.toString());
bw.newLine();
}
bw.flush();
bw.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
});
long et = System.currentTimeMillis();
System.out.println(“Time Taken =” + (et - st));
} catch (Exception e) {
e.printStackTrace();
}

But its taking a lot of time to write a single row. a hell lot of time any other means or ways toread cell values and write to txt as pipeline seperated of an excel of500k+ rows.

The way its said in documents of xlsx to csv conversion it throws error as below as below,

14:17:20.132 [main] INFO AppMain - Loaded File -->C:\Users\Documents\300kexcel\sample.xlsx
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.cells.b.a.d.zh.b(Unknown Source)
at com.aspose.cells.b.a.d.zh.c(Unknown Source)
at com.aspose.cells.b.a.d.zh.b(Unknown Source)
at com.aspose.cells.b.a.d.zo.a(Unknown Source)
at com.aspose.cells.b.a.d.zo.a(Unknown Source)
at com.aspose.cells.zun.a(Unknown Source)
at com.aspose.cells.zun.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)

@aymarzapak,
Please share your sample file with us for our testing. We will reproduce the problem and provide our feedback after analysis.

My file is about 200mb can i upload it

@aymarzapak,
Upload it to some public file sharing server and share the download link here.

unfrotunately all those links are barred in my system to upload it :frowning: Can you suggest me better way to laod larger files , right now i am using memorySetting but still its taking a load of time to process row by row

@aymarzapak,
I am afraid that there is no alternate available and you have to upload it to any of the file sharing server. Aspose does not provide any file sharing facility for such a huge file therefore I am afraid we cannot suggest you any option in this regard.

@aymarzapak,

We think you have already created new thread for your issue where you are able to sort it out by following the suggestions and sample code there.

In case, you are still finding any issue, feel free to write us back with details and samples, we will be happy to assist you.