Skip to content

Commit 44390a7

Browse files
author
jossonsmith
committed
Fixed bug that generated JavaScript files are not UTF-8 encoded.
1 parent fc32006 commit 44390a7

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/net/sf/j2s/core/compiler/Java2ScriptCompiler.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.io.FileInputStream;
55
import java.io.FileNotFoundException;
66
import java.io.FileOutputStream;
7-
import java.io.FileWriter;
87
import java.io.IOException;
98
import java.util.ArrayList;
109
import java.util.HashMap;
@@ -368,20 +367,13 @@ public static void outputJavaScript(ASTScriptVisitor visitor, DependencyASTVisit
368367
}
369368
}
370369
File jsFile = new File(folderPath, elementName + ".js"); //$NON-NLS-1$
371-
FileWriter fileWriter = null;
372370
try {
373-
fileWriter = new FileWriter(jsFile);
374-
fileWriter.write(js);
371+
FileOutputStream fos = new FileOutputStream(jsFile);
372+
fos.write(new byte[] {(byte) 0xef, (byte) 0xbb, (byte) 0xbf}); // UTF-8 header!
373+
fos.write(js.getBytes("UTF-8"));
374+
fos.close();
375375
} catch (IOException e) {
376376
e.printStackTrace();
377-
} finally {
378-
if (fileWriter != null) {
379-
try {
380-
fileWriter.close();
381-
} catch (IOException e) {
382-
e.printStackTrace();
383-
}
384-
}
385377
}
386378

387379
String[] classNameSet = dvisitor.getClassName();

0 commit comments

Comments
 (0)