So I'm writing a tool for a game for modding, it's working all fine, but I got a problem with writing Strings to a file. The game needs the file encoded in UTF-16LE BOM, so my code looks something like this:
public void save()
{
FileOutputStream fos = null;
byte[] buffer = null;
try {
fos = new FileOutputStream(new File("data//backup.txt"));
} catch (FileNotFoundException ex) {
}
try
{
fos.write((byte)255);
fos.write((byte)254);
fos.write("\"lang\"\n".getBytes("UTF-16LE"));
String s = "";
for(int i = 1;i<fileContent.size();i++)
{
s = fileContent.get(i);
fos.write(s.getBytes("UTF-16LE"));
fos.write(System.getProperty("line.separator").getBytes("UTF-16LE"));
}
fos.close();
}
catch(Exception e){}
}
fileContent is a ArrayList of Strings, containing NO line separators (I checked this multiple times). So my problem is, that there are written too many line separators to the file. Instead of e.g.:
a
b
I get something like:
a
b
Any ideas, what I'm doing wrong?