-1

I have a problem with my Csv file, In my app I want to insert all the data base to a Csv file and send it via email. Every thing goes great except one thing- the encoding of the file isn't UTF-8 so every time I send the file via email I have to change the encoding my self.

I didn't find any way I can change the encoding when I create the file, so I wanna know if it is possible to insert a csv file to the resource folder in my app with encoding UTF-8, and then send this file via email.

So what I am asking is, Is it possible? And if so, how can I do it?

I am currently creating the csv file with openCSV String csv = android.os.Environment.getExternalStorageDirectory().getAbsolutePath(); try { File myFile = new File(csv + "/Data.csv"); myFile.createNewFile(); CSVWriter writer = new CSVWriter(new FileWriter(myFile), ','); }

Fisher
  • 23
  • 1
  • 6
  • I searched for a long time, I didn't find an answer. do you have an example I can see? – Fisher Oct 18 '15 at 20:37
  • I am not reading the csv file in my phone, I am just creating and writing in it, then I send it to an email and open the file in my computer. I don't know where you found the answer, but I cant find any piece of code that changes the encoding, maybe im an idiot, Idk ):. Can you send me a link of the answer you found? – Fisher Oct 18 '15 at 22:30
  • Ok tell me if I am right, this code creates a file reader that reads the file with UTF-8 encoding, so when I want to get a line or something from the csv file Ill get the string or the line with UTF-8 encoding and use it in my code or what ever... If this is the thing that code does It wont help. When I open the File in my computer the default encoding isn't UTF-8 and every time I send the file via email I have to change the encoding(in my computer) If this code you sent me suppose to do what I said then it didn't work ): And I don't know why.... and ty for the help anyways – Fisher Oct 18 '15 at 23:13
  • Thank you very much, But it doesn't seem to work... – Fisher Oct 19 '15 at 00:58
  • The last link you sent me had no effect... Ill try this last link you sent – Fisher Oct 19 '15 at 16:24
  • Ok Thank you very much, this link worked. And thank you for your patience. – Fisher Oct 19 '15 at 16:38

1 Answers1

0

I removed the lengthy comments we exchanged while searching a solution to your problem.

You have to use a different constructor on CSVWriter, then you are able to specify the file encoding. Defining the file.encoding when the JVM gets launched should help too:

java -Dfile.encoding=UTF-8 -jar foo.jar

There is already a documented solution to your problem on stack overflow which shows an example: setting a UTF-8 in java and csv file

Community
  • 1
  • 1
Marged
  • 10,577
  • 10
  • 57
  • 99