0

hi i have use the first code from the following post How to create an Excel file based on CSV file using Java?

but i want to set the delimiter of the input CSV file with arg for example if the delimiter is not a comma but ! i would like to set it manually with args an the xls file split the line when sees ! instead for comma could you please help?

0

1 Answer 1

0

You can instantiate the CSVReader with this constructor:

public CSVReader(Reader reader, char separator)

So you only need to pass your argument to this constructor. A very basic example:

char separator = argv[0].charAt(0);
CSVReader reader = new CSVReader(new FileReader("data.csv"), separator);

It will take the first character of the first argument string, and make a char from it. Don't forget to add safety checks.

In this case, if you run your program as:

java -cp . com.example.Main "!"

It will read data.csv as a ! delimited CSV file.

Sign up to request clarification or add additional context in comments.

2 Comments

hi again one more question i try to run the code with java 1.5 and said that in 1.5 jdk i cant run try with resources. could you please help me how to resolve this problem ? in java 1.7 works like a charm but i need to run it in java1.5
Well, don't use try-with-resources, just close your resources manually in the finally block.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.