N
Nishi Bhonsle
Hi:
In an servlet application, I need to pass a UTF-8 encoded writer to an Java API, which will process the contents of a file through the writer. Thereafter, the file can be saved on the users machine through a OS specific "File Save As" dialog box. The UTF-8 encoding takes into account non-ascii data(users in non-english locale).
I noticed that this works fine on IE as well as Netscape for English locale but for non-english locale, IE does not pop up the FileSave As box but displays the contents of the file in a same browser window whereas Netscape saves the file as a 0 byte file.
Can someone please let me know what could be wrong with the below code?
//this page has the "download" property set, so the temp.txt will be saved on the users machine by providing the user with a File //SaveAs dialog box.
try {
java.io.Writer utf8Writer = new OutputStreamWriter(new FileOutputStream("temp.txt",false), "UTF-8");
<APIname>(utf8Writer); //API call
utf8Writer.flush();
java.io.InputStream is = new BufferedInputStream(new FileInputStream("temp.txt"));
BufferedReader in = new BufferedReader(new InputStreamReader(is));
//Make sure that the contents get saved in readable format
String inputLine;
String newLine = " ";
String newline = System.getProperty("line.separator");
while ((inputLine = in.readLine()) != null)
{
newLine=newLine.concat(inputLine);
newLine=newLine.concat(newline);
}
StringBufferInputStream sis = new StringBufferInputStream(newLine);
//set the stream for download to be sis
//download the temp.txt through a download bean
is.close();
utf8Writer.close();
}
catch (Throwable t)
{
handleError(t);
}
}
In an servlet application, I need to pass a UTF-8 encoded writer to an Java API, which will process the contents of a file through the writer. Thereafter, the file can be saved on the users machine through a OS specific "File Save As" dialog box. The UTF-8 encoding takes into account non-ascii data(users in non-english locale).
I noticed that this works fine on IE as well as Netscape for English locale but for non-english locale, IE does not pop up the FileSave As box but displays the contents of the file in a same browser window whereas Netscape saves the file as a 0 byte file.
Can someone please let me know what could be wrong with the below code?
//this page has the "download" property set, so the temp.txt will be saved on the users machine by providing the user with a File //SaveAs dialog box.
try {
java.io.Writer utf8Writer = new OutputStreamWriter(new FileOutputStream("temp.txt",false), "UTF-8");
<APIname>(utf8Writer); //API call
utf8Writer.flush();
java.io.InputStream is = new BufferedInputStream(new FileInputStream("temp.txt"));
BufferedReader in = new BufferedReader(new InputStreamReader(is));
//Make sure that the contents get saved in readable format
String inputLine;
String newLine = " ";
String newline = System.getProperty("line.separator");
while ((inputLine = in.readLine()) != null)
{
newLine=newLine.concat(inputLine);
newLine=newLine.concat(newline);
}
StringBufferInputStream sis = new StringBufferInputStream(newLine);
//set the stream for download to be sis
//download the temp.txt through a download bean
is.close();
utf8Writer.close();
}
catch (Throwable t)
{
handleError(t);
}
}