I’ve very little Java experience. I’m trying to force a document to be read as UTF-8, but have come stuck trying to hook the InputStream reader to the document builder.
Here’s what I have so far:
import javax.xml.xpath.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
if( pathToFile == null ) throw new Exception("You must supply a pathToFile parameter");
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputStreamReader in = new InputStreamReader( new FileInputStream( pathToFile ), "utf-8" );
BufferedReader reader = new BufferedReader ( new InputStreamReader ( in ) );
Element records = builder.parse(reader).getDocumentElement();
Be grateful if someone can provide me with some pointers
Assuming this is Groovy, you can rid yourself of a lot of the Java cruft:
Not tried it, but:
should work…