Results 1 to 2 of 2
  1. #1
    simon is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default java.io.UTFDataFormatException

    When I try to create a file and try to parse it an error appears
    this is my code:

    Java Code:
    FileWriter fw =null;
    File file=null;
    BufferedWriter bw=null;
    String nodeName="";
    String nodeval="";
    System.out.println("XML String" + XMLString);
    try {
    double ran = Math.random();
    fw= new FileWriter("content.xml");
    file = new File("content.xml");
    bw = new BufferedWriter(fw);
    bw.write(XMLString);
    bw.flush();
    Document doc = docBuilder.parse(file); --
    and the exception is that:
    Java Code:
    java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.
    at org.apache.xerces.impl.io.UTF8Reader.invalidByte
    (Unknown Source)
    at org.apache.xerces.impl.io.UTF8Reader.read
    (Unknown Source)
    at org.apache.xerces.impl.XMLEntityScanner.load
    (Unknown Source)
    at org.apache.xerces.impl.XMLEntityScanner.peekChar
    (Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanCDATASection
    (Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch
    (Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument
    (Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:172)
    at com.supportap.blp.ParserUtil.parseXMLContent(ParserUtil.java:128)
    at com.supportap.blp.ParserUtil.main(ParserUtil.java:176)
    any ideas?

  2. #2
    oregon is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default

    try:
    Java Code:
    fw = new OutputStreamWriter(new FileOutputStream("content.xml"),"utf-8");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •