• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Writing a file without Byte Order Mark.

 
Ranch Hand
Posts: 244
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading a file line by line and splitting it up into multiple files. The output files are xml files but because I'm inadvertently including a BOM Byte Order Mark in my output files I'm getting an error in another application which is trying to load them.

I have found many many links to methods to remove the BOM from existing files or a workaround for reading them. However I'm trying to avoid the problem by finding an alternative way to create the output files in the first place.

I'm developing on a Mac and the program will eventually run on Windows machine. I've tried changing the character set in the code to UTF-8, UTF-16BE and even ASCII. Not sure if I should try writing bytes instead.

 
Saloon Keeper
Posts: 10310
217
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly suggest that you rewrite the program to use Files.newBufferedWriter() created with a Charset.forName("UTF-8").

Not only should that work, it also prevents the application from repeatedly opening and closing the output files. For. Every. Line. This will significantly speed up the program.
 
David Garratt
Ranch Hand
Posts: 244
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked for me - many thanks.

Dave
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!