|
-
April 9th, 2010, 01:21 PM
#1
InputStreamReader, Charsets, and a surprise character
I'm trying to write a parser that will read some xml code, altering only certain things, and printing the results to another file. I'm aware of xml parsers etc, but I needed something very specific. I'm using an InputStreamReader and a FileOutputStream with a PrintStream.
Demo/Test Sample
Code:
<xml>
±
</xml>
Doing it with no charset specified (default Cp1252) results in :
Code:
<xml>
±
</xml>
Why is another character added?
Simplified version of my code. This should open a file, read it, and output it to another file.
Code:
File file = new File("myfile.xml");
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "Cp1252"));
FileOutputStream out = new FileOutputStream("results.xml");
PrintStream p = new PrintStream(out, true, "Cp1252");
String textLine = new String();
while ((textLine = reader.readLine()) != null){
p.println(textLine);
}
reader.close();
p.close();
Thanks for the time
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|