Skip to content

Commit 23c29ae

Browse files
committed
U add new auxiliary method writeStringToFileWithBOM
1 parent a43078f commit 23c29ae

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/io/github/fvarrui/javapackager/utils/FileUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,20 @@ public static boolean exists(File file) {
326326
public static boolean folderContainsFile(File folder, String filename) {
327327
return new File(folder, filename).exists();
328328
}
329+
330+
/**
331+
* Writes String to a file in UTF-8 including BOM
332+
* @param output Output file
333+
* @param data Input string
334+
* @throws Exception if something goes wrong
335+
*/
336+
public static void writeStringToFileWithBOM(File output, String data) throws Exception {
337+
FileOutputStream fileOutputStream = new FileOutputStream(output);
338+
// write utf-8 BOM
339+
byte[] uft8bom = { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
340+
fileOutputStream.write(uft8bom);
341+
fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
342+
fileOutputStream.close();
343+
}
329344

330345
}

0 commit comments

Comments
 (0)