Hello,
I have a problem with character encoding. I'm using servlet to read file and write its content to jsp textarea.
This is my read file method:
public void readFilesText(String inPutFile){
getTextBetweenBody().clear();
BufferedReader in1 = null;
String eil = "";
try{
File file = new File(inPutFile);
in1 = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
while ((eil = in1.readLine()) != null){
getTextBetweenBody().add(eil);
}
in1.close();
} catch (Exception e){
log.error(e);
}
}
When read file and write file's content to textarea, it is ok. But when I write that content from textarea to another file, my symbols are encoded in UTF-8. But they look like spesific UTF-8 simbols.
There are some words that written from textarea to the file:
NeÃÂ
þinomas
sutartï
teisÄs į viltį
There are same words that suposed to be written to the file like below. It is lithuanian symbols.
Neinomas
sutartį
teisė į viltį
Here is my writing to the file servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
realPath = getServletContext().getRealPath(EDITED_FILES_DIR);
StringBuffer text = new StringBuffer(request.getParameter("iterpimas"));
String homeDir = realPath + "/Edited.xml";
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(homeDir), "UTF-8"));
br.write(text.toString());
br.flush();
br.close();
request.setAttribute("HomeDir", homeDir);
RequestDispatcher rd = request.getRequestDispatcher("/inserted.jsp");
rd.forward(request, response);
}
And this is jsp textarea code:
<form name="form" action="XMLInserter.srv" method="post">
<div id="content">
<textarea spellcheck="false" class="textarea2" name="iterpimas" cols=140 rows=20><%for (String text : rf.getTextBetweenBody()){out.println(text);}%></textarea>
<input type="submit" name="pakeitimai" class="iterpti" value="Atlikti pakeitimus">
</div>
</form>
And a question: How can write a text from textarea to the file without this UTF-8 spesificly encoded symbols?
Any help would be very appreciate.
Edited by: peliukasss on Apr 28, 2010 12:15 PM