chiark / gitweb /
Explicitly specify output encoding in marketcheck.
authorHenrik Tunedal <tunedal@gmail.com>
Sun, 6 Feb 2011 04:13:44 +0000 (05:13 +0100)
committerHenrik Tunedal <tunedal@gmail.com>
Sun, 6 Feb 2011 04:13:44 +0000 (05:13 +0100)
FileWriter uses "the default character encoding", which seems like
asking to live in interesting times. The program assumes UTF-8 when
it reads the file, so it should obviously do the same when it writes
it back.

marketcheck/test.java

index 2a34a67d7a8b05df29badb42da7791746971900d..1afa631c495cfe1fb24cce9544c5d98b404b6400 100644 (file)
@@ -101,10 +101,13 @@ class test {
 \r
                                 if (changed) { \r
                                     System.out.println("..updating");\r
-                                    File of = new File(filespec);\r
-                                    BufferedWriter wi = new BufferedWriter(new FileWriter(of));\r
+                                    FileOutputStream fo = new FileOutputStream(filespec);\r
+                                    OutputStreamWriter osr = new OutputStreamWriter(fo, "UTF-8");\r
+                                    BufferedWriter wi = new BufferedWriter(osr);\r
                                     wi.write(output.toString());\r
                                     wi.close();\r
+                                    osr.close();\r
+                                    fo.close();\r
                                 }\r
 \r
                             }\r