opencsv

CSVReader - bug when using " for escape char

我与影子孤独终老i 提交于 2019-12-02 12:56:12
问题 I am using OpenCSV. I have a CSVReader trying to parse a CSV file. That file has quote char " and separator char , and escape char also " . Note that the CSV contains cells like: "ballet 24"" classes" "\" which actually represent these values: ballet 24" classes \ Example: "9/6/2014","3170168","123652278","Computer","2329043290","Bing and Yahoo! search","22951990789","voice lesson","Broad","0.00","0","1","3.00","0.00","0.00","0.00","7","0","","" "9/6/2014","3170168","123652278","Smartphone",

Is there any way to change value of a particular cell in a csv file in java?

走远了吗. 提交于 2019-12-02 12:31:33
I have gone through other questions regarding this on StackOverflow but libraries mentioned there only allow to read or write. Some of them do allow partial read or write like SuperCSV but no library can be used for updating value of a particular cell. Is there some other library that can be used or do I need to do it manually? Read in the CSV, modify the cell you want, then write it back to the file. No, there is no way to directly update the cell in CSV file. You can read CSV line by line and then column by column , update the cell (content) and write to a new file. And if you know the

OpenCsv reading file with escaped separator

做~自己de王妃 提交于 2019-12-02 11:45:22
Am using opencsv 2.3 and it does not appear to be dealing with escape characters as I expect. I need to be able to handle an escaped separator in a CSV file that does not use quoting characters. Sample test code: CSVReader reader = new CSVReader(new FileReader("D:/Temp/test.csv"), ',', '"', '\\'); String[] nextLine; while ((nextLine = reader.readNext()) != null) { for (String string : nextLine) { System.out.println("Field [" + string + "]."); } } and the csv file: first field,second\,field and the output: Field [first field]. Field [second]. Field [field]. Note that if I change the csv to

Appending to CSV file without headers

橙三吉。 提交于 2019-12-02 10:11:31
问题 I am using opencsv to write a Java bean to a CSV file with headers. The file name contains the current date. If the user runs it for a second time in the same day, it appends to the file but adds another header line. How do I append to the file but without the column headers. public class CSVExport { final File USERHOME = new File(System.getProperty("user.home")); final List<saleExport> listSaleExport = new ArrayList<>(); final ObjectMapper mapper = new ObjectMapper(); public void

Editing CSV Files (Design Implementation)

房东的猫 提交于 2019-12-02 09:26:25
Im starting to design a program that will automate the process of finding and identifying strings correctly based on similar strings and their identities that have been found and saved into a master CSV/Excel file. Right now I want to design it properly so I dont run into issues later when implementing the CSV/Excel read writing part. I will probably use OpenCSV to write and read the files, so my question is more about how I can edit the file. Last time I dealt with editing CSV files I had to rewrite each line to a new or existing file rather than just editing a specific line. Is this the only

How do I skip white-space only lines and lines having variable columns using supercsv

牧云@^-^@ 提交于 2019-12-02 04:10:42
I am working on CSV parser requirement and I am using supercsv parser library. My CSV file can have 25 columns(separated by tab(|)) and up to 100k rows with additional header row. I would like to ignore white-space only lines and lines containing less than 25 columns. I am using IcvBeanReader with name mappings(to set csv values to pojo) and field processors(to handle validations) for reading a file. I am assuming that Supercsv IcvBeanReader will skip white space lines by default. But how to handle if a row contains less than 25 column numbers? You can easily do this by writing your own

A disk error occurred during a write operation. (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))

假如想象 提交于 2019-12-01 21:23:14
问题 I am using EPPlus to read .csv file in vb.net. When I run this code, I get the error "A disk error occurred during a write operation. (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))" Here is my code : Public Function ImportExcelSheet(ByVal filePath As String) As DataTable Dim dtImportData As New DataTable() Try 'If csv file have header then "true" else "false" Dim hasHeader As Boolean = True Using pck = New OfficeOpenXml.ExcelPackage() Using stream = File.OpenRead(filePath) pck.Load

opencsv writing file with some quoted elements and others unquoted

核能气质少年 提交于 2019-12-01 20:42:39
问题 Does anyone have experience using opencsv in Java to write a csv file where only some of the elements need to be double quoted? The desired output I am looking to test is to make a file that would read: 1,"two",three but when I try the following code writer = new CSVWriter(new FileWriter("yourfile.csv"), ',',CSVWriter.NO_QUOTE_CHARACTER); String[] entries = {"1","\"two\"","three"}; writer.writeNext(entries); writer.close(); the following output occurs 1,""two"",three Thoughts? 回答1: These

Reading CSV file in resources folder android

无人久伴 提交于 2019-12-01 15:51:27
I am developing an android app in netbeans. I am trying to read CSV file using opencsv. When I put the file in resources folder and try to read it from there, there's an error while building saying invalid resource directory. Where should I store csv file so that it can be read each time the app starts? you should put csv file in assets folder .. InputStreamReader is = new InputStreamReader(getAssets() .open("filename.csv")); BufferedReader reader = new BufferedReader(is); reader.readLine(); String line; while ((line = reader.readLine()) != null) { } Some advices; Create an object for holding

Reading CSV file in resources folder android

泪湿孤枕 提交于 2019-12-01 14:52:31
问题 I am developing an android app in netbeans. I am trying to read CSV file using opencsv. When I put the file in resources folder and try to read it from there, there's an error while building saying invalid resource directory. Where should I store csv file so that it can be read each time the app starts? 回答1: you should put csv file in assets folder .. InputStreamReader is = new InputStreamReader(getAssets() .open("filename.csv")); BufferedReader reader = new BufferedReader(is); reader