I need to replace a csv file on unix with xlsx file. I have created a java service and I am using opencsv to read the csv file. I am able to read the file locally and convert it to xlsx but when I give the complete unix path, it gives me an error that the system cannot find the path specified.
Below are the 3 approaches I have tried separately. csvFilePath is a string variable that has the path /home/file/abc.csv
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(csvFilePath)));
FileReader fileReader= new FileReader(csvFilePath);
I used pub.file:getFile to get the csv data in stream and then used pub.io:stringToReader to convert the stream in InputStreamReader object and passed this object to java service. This is how I am trying to fetch:
I don’t want to mix flow service and java service and just want to do this job using one java service. Can anyone please tell me what wrong I am doing here?
I think you have to configure the IS so that it can read files in the desired directory via file:getFile. With a custom java service you can read any directory.
Thank you all for your suggestions. I am using WM 9.10 version. Earlier I was creating a csv file from json but now I need to send an xlsx file. My input is json that I get from calling a third party API. So I have been asked to keep everything same and convert the final csv file to xlsx file and delete the csv file. I want a single java service to do this rather than a combination of flow service and java service to read csv and write xlsx file. For this I am using apache poi for excel and opencsv jar to read csv.
Today I am able to progress on reading the file.
I used Path class from java.nio.file.Paths; package and converted it to path object
Path path = Paths.get(csvFilePath);
csvReader = new CSVReader(new FileReader (path.toString()));
Now I am stuck at writing the excel file.
Workbook workBook = new SXSSFWorkbook();
SXSSFSheet sheet = (SXSSFSheet) workBook.createSheet(“Sheet”);----> giving null pointer exception
This works fine on local and is successfully writing data to xlsx file however on unix filesystem I am getting null pointer exception.
I used Workbook workBook = new XSSFWorkbook();-----> still it didn’t work
but when I used Workbook workBook = new HSSFWorkbook();
it worked and I was able to create xls file on server. However I need xlsx format
Do you think If I get the approval to install font, it will resolve my issues? Does anybody has any better approach for example script? I am not able to understand why xls file gets created but not xlsx. I have imported all correct jars and classes of apache poi framework.