L
loial
I am reading and writing a files which contains the U.K pound sign £
But it is not being written correctly to the output file, even though
I am specifying UTF-8
Should this code work?
Reading :
InputStream fr;
BufferedReader br;
try {
fr = new FileInputStream(strDocumentFile);
br = new BufferedReader(new InputStreamReader(fr, "UTF-8"));
}
catch (java.io.FileNotFoundException e) {
String strReturn = "FileNotFoundException trying to open " +
strInFile;
traceError (strReturn);
return strReturn;
}
catch (java.io.UnsupportedEncodingException e) {
String strReturn = "FileNotFoundException trying to open " +
strInFile;
traceError (strReturn);
return strReturn;
}
String s = null;
do {
try {
s = br.readLine();
} catch (Exception e) {
String strReturn = getExceptionStackString(e) + " while
reading " + strInFile;
traceError (strReturn);
return strReturn;
}
Writing :
OutputStream fw;
BufferedWriter bw;
try {
fw = new FileOutputStream(strOutFile,true);
bw = new BufferedWriter(new OutputStreamWriter(fw, "UTF-8"));
}
catch (java.io.FileNotFoundException e) {
strReturn = "FileNotFoundException trying to open " +
strOutFile;
traceError (strReturn);
return strReturn;
}
catch (java.io.UnsupportedEncodingException e) {
strReturn = "FileNotFoundException trying to open " +
strOutFile;
traceError (strReturn);
return strReturn;
}
bw.write(s);
But it is not being written correctly to the output file, even though
I am specifying UTF-8
Should this code work?
Reading :
InputStream fr;
BufferedReader br;
try {
fr = new FileInputStream(strDocumentFile);
br = new BufferedReader(new InputStreamReader(fr, "UTF-8"));
}
catch (java.io.FileNotFoundException e) {
String strReturn = "FileNotFoundException trying to open " +
strInFile;
traceError (strReturn);
return strReturn;
}
catch (java.io.UnsupportedEncodingException e) {
String strReturn = "FileNotFoundException trying to open " +
strInFile;
traceError (strReturn);
return strReturn;
}
String s = null;
do {
try {
s = br.readLine();
} catch (Exception e) {
String strReturn = getExceptionStackString(e) + " while
reading " + strInFile;
traceError (strReturn);
return strReturn;
}
Writing :
OutputStream fw;
BufferedWriter bw;
try {
fw = new FileOutputStream(strOutFile,true);
bw = new BufferedWriter(new OutputStreamWriter(fw, "UTF-8"));
}
catch (java.io.FileNotFoundException e) {
strReturn = "FileNotFoundException trying to open " +
strOutFile;
traceError (strReturn);
return strReturn;
}
catch (java.io.UnsupportedEncodingException e) {
strReturn = "FileNotFoundException trying to open " +
strOutFile;
traceError (strReturn);
return strReturn;
}
bw.write(s);