Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Moe1
Contributor II
Contributor II

convert CSV to UTF BOM

I'm trying to convert my generated text file to UTF with BOM, I tried in custom "UTF-BOM" and "UTF-8-BOM" but it is throwing unsupported encoding error... I tried this java code but it is writing empty file:

 

String filename = "/myTXTfilepath/file.txt";
String content="";
byte[] bytes = content.getBytes();

try (OutputStream out = new FileOutputStream(filename)) {

// write a byte sequence
out.write(0xEF);
out.write(0xBB);
out.write(0xBF);

out.close();
} catch (IOException e) {
e.printStackTrace();
}

Labels (2)
5 Replies
Anonymous
Not applicable

Hi @Moe ,

 

Instead of out.write can you use out.print() for UTF-8 BOM.

 

or instead of OutputStream please use PrintWriter class.

 

PrintWriter out = new PrintWriter(new File(filePath), "UTF-8");
out.write(csvFileContent);

 

Thanks and Regards,

Subhadip

Anonymous
Not applicable

Hello Moe....!

My original CSV files are encoded with UTF8-BOM, this is so Excel can recognize the Unicode characters (If its just encoded with UTF8 then Excel does not recognize the Unicode characters).

My issue is that with a UTF8 encoded CSV file, when you click save in Excel it gives you a popup option to keep the original formatting. However if the file is UTF8-BOM encoded then clicking the save is instant and there is no option to keep the formatting. The CSV file then has it commas replaced with tabs.

 

Thank You THOP TV & ONMOVIES

Moe1
Contributor II
Contributor II
Author

Thanks, I tried PrintWriter, FileWriter with BufferedReader but of them created a file with UTF8 encoding and not utf8 with BOM

Anonymous
Not applicable

Anonymous
Not applicable

Awesome it usefull to make strong Article. Thank you writer.

- Nth Sports App