Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Writing a file without Byte Order Mark.

 
Ranch Hand
Posts: 261
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: 12013
257
  • 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: 261
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked for me - many thanks.

Dave
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic