• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Export the multilanguage (Estonian , Lithunain, Latvian)data to CSV file using Outputstreamwriter

 
vinay babu reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am currently facing one issue with Export the data to csv, please help me out or give me idea or suggestion to solve the same

The problem here it is :

we are newly introducing 4 more new languages(Estonian, lithunaina, Latvian, polish) to existing application, i have a list screen where i am export the same list screen data to CSV(comma seperated format) file. The data export correctly as shows in List screen but when i opened the csv - the header labels (names) displayed with '?' marks. I have tried some of possible ways to solve the same, but i have no luck to crack this issue. I have tried to given as UTF-8 encoding for java.io.Outputstreamwrite class, even then my problem has nt solved.

Please post me any solution if you have.



 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does it show the question marks? Does that piece of software know that the file is in UTF-8? It may assume that it's in ASCII.
 
vinay babu reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you reply

It shows the '?' marks in CSV file

Here is the code i made :

OutputStreamWriter writer = new OutstreamWriter(out,"UTF-8")

StrinBuffer sb= new StringBuffer();

sb.append(str).append(Quote).append(SEP)

writer.write(sb);

Please let me know any idea, is CSv will support all these languages
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I meant was "what piece of software are you using to look at the CSV file?" Excel? OpenOffice? A console window?
 
vinay babu reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply

Microsoft Excel 2007
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excel apparently has problems with UTF-8 CSV files; try UTF-16 instead. You may wish to provide a list of various encodings for the user to choose from, like Cp1252, ISO-8859, UTF-8, UTF-16 etc.
 
vinay babu reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same output with '?' marks.. do you have any example code to resolve.


 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has nothing to do with code; you need to look into how to make Excel work with different encodings in CSV files. A web search finds numerous hits for that kind of problem.
 
vinay babu reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi.. Thanks for all quick responses...
Finally we find out the solution ... here it is..

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Properties;
import java.io.*;


public class WriteToFile {
public static void main(String[] args) throws Exception {
Properties p = new Properties();
FileInputStream fr = new FileInputStream("D:\\EclipseWorkSpace\\Workspace\\Test\\src\\test\\acqtransaction\\package_lv_unicode.properties");
p.load(fr);
FileOutputStream fos = new FileOutputStream("c:\\out.csv");

byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF }; // BOM values
fos.write(bom); // adds BOM

Writer out = new BufferedWriter(new OutputStreamWriter(fos, "UTF8"));
for (Object key : p.keySet()) {
Object val = p.get(key);
out.write("\"" + key + "\",\"" + val + "\"\n"); // adds key and value
}
out.close();
}

}

What is missing is the BOM (For example look at: http://en.wikipedia.org/wiki/UTF-8 look for BOM). If you open the CSV file you made for example in Notepad ++ or Notepad you will see that the special chars shows fine. But because of the missing BOM Excel can’t open the CSV file correct.

You should be able to fix the CSV problem with this example. Remember it’s just an example, the BOM part is the essential.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags next time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic