5/27/2023 0 Comments Convert csv to json![]() ![]() Or option two using try-with resource import java.io.BufferedReader ![]() Logger.getLogger(()).log(Level.SEVERE, null, ex) String tabWrite = jsonScript.split("\n") JsonScript = jsonScript.substring(0, jsonScript.length() - 2) String jsonScript = "constant header of json content" JsonFile = new BufferedWriter(new FileWriter("converted.txt")) import java.io.BufferedReader ĬsvFile = new BufferedReader(new FileReader("DataTextCsv.csv")) See the following, you had your close methods in the wrong location. I'm conscious that it would be simpler to use more specific libraries, but as I'm new with Java, I wasn't able to find the right package to download and install ![]() The application can correctly read the first line of the csv file but can not continue till the end and I continuously get this error (even if I try to set all my csv data in one line: Exception in thread "main" java.io.IOException: Stream closedĪt java.io.BufferedReader.ensureOpen(Unknown Source)Īt java.io.BufferedReader.readLine(Unknown Source)Īt CSVConverter.main(CSVConverter.java:17) JsonScript=jsonScript.substring(0,jsonScript.length()-2) String jsonScript="constant header of json content" Here is a portion of my code: BufferedReader csvFile= new BufferedReader(new FileReader("DataTextCsv.csv")) īufferedWriter jsonFile=new BufferedWriter(new FileWriter("converted.txt")) I chose to simplify by using a classic method with BufferedReader and BufferedWriter. I'm trying to create a Java application to convert Excel/csv file content to JSON format,Īs all my output json files have the same header. ![]()
0 Comments
Leave a Reply. |