FileWriter & UTF-16

Hi, after making an instance of FileWriter, a simple file to go along with it e.g., :
FileWriter writer = new FileWriter("AFile.txt");
and then returning the encoding via:
String aStringHere = writer.getEncoding();
When I display this string it is "Cp1252", which from looking around is "Windows Latin". Could someone tell me why is this the default (I need UTF-16, is it supported?!?) and is it possible to change the encoding for FileWriter?
Thanks :-)
necro_ignis

I do not recommend changing that...
If you want to, you will have to change JVM envioronment property... so when you start your java, do this:
-Dfile.encoding=ISO-8859-1

Similar Messages

  • Writing a file in UTF-8 Format using FileWriter

    Hi,
    I am trying to write some data to the file system using a filewriter object. I want the file to be stored in UTF-8 encoding. Please give me some pointers regarding the same.
    Best Regards,
    Pradeep

    First you have to declare that you will use UTF8 :
    OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(myFilePath,true),"UTF8");Then you can write in you file in UTF8.
    The problem is that when you open the file with an editor like Crimson or UltraEdit, it says that your file is encoded in ASCII ... even if your stream had well been saved in UTF8.
    To be sure that your file format is UTF8, you have to had at the beginning of your file 3 bytes : EF, BB and BF :
    byte[] x = new byte[3];
    x[0] = (byte) (Integer.parseInt("EF",16));
    x[1] = (byte) (Integer.parseInt("BB",16));
    x[2] = (byte) (Integer.parseInt("BF",16));
    osw.write(new String(x,"UTF8"));Here my "complete" code :
    String myFilePath = "........";
    String myText = "............";
    OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(myFilePath,true),"UTF8");
    System.err.println("osw encoding : "+osw.getEncoding()); //just to be sure of the encoding
    byte[] x = new byte[3];
    x[0] = (byte) (Integer.parseInt("EF",16));
    x[1] = (byte) (Integer.parseInt("BB",16));
    x[2] = (byte) (Integer.parseInt("BF",16));
    osw.write(new String(x,"UTF8"));
    osw.write(new String(myText));
    osw.close();I think you can use OutputStreamWriter instead of FileWriter as FileWriter inherits of OutputStreamWriter.

  • Need help to read and write using UTF-16LE

    Hello,
    I am in need of yr help.
    In my application i am using UTF-16LE to export and import the data when i am doing immediate.
    And sometimes i need to do the import in an scheduled formate..i.e the export and imort will happend in the specified time.
    But in my application when i am doing scheduled import, they used the URL class to build the URL for that file and copy the data to one temp file to do the event later.
    The importing file is in UTF-16LE formate and i need to write the code for that encoding formate.
    The problem is when i am doing scheduled import i need to copy the data of the file into one temp place and they doing the import.
    When copying the data from one file to the temp i cant use the UTF-16LE encoding into the URL .And if i get the path from the URl and creating the reader and writer its giving the FileNotFound exception.
    Here is the excisting code,
    protected void copyFile(String rootURL, String fileName) {
    URL url = null;
    try {
    url = new URL(rootURL);
    } catch(java.net.MalformedURLException ex) {
    if(url != null) {
    BufferedWriter out = null;
    BufferedReader in = null;
    try {
    out = new BufferedWriter(new FileWriter(fileName));
    in = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;
    do {
    line = in.readLine();
    if(line != null) {
    out.write(line, 0, line.length());
    out.newLine();
    } while(line != null);
    in.close();
    out.close();
    } catch(Exception ex) {
    Here String rootURL is the real file name from where i have to get the data and its UTF-16LE formate.And String fileName is the tem filename and it logical one.
    I think i tried to describe the problem.
    Plz anyone help me.
    Thanks in advance.

    Hello,
    thanks for yr reply...
    I did the as per yr words using StreamWriter but the problem is i need a temp file name to create writer to write into that.
    but its an logical one and its not in real so if i create Streamwriten in that its through FileNotFound exception.
    The only problem is the existing code build using URL and i can change all the lines and its very difficult because its vast amount of data.
    Is anyother way to solve this issue?
    Once again thanks..

  • Jdev11.1.1.6.0-Error while translating message to native format-FileWrite

    Im reading a file from a service and transforming the data and writing them into a file through the external reference using a Mediator component.
    I have no problem while building or deploying.
    But while executing I get an error as follows:
    Non Recoverable System Fault :
    Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'WriteAppointmentRequestInLogFile' failed due to: Translation Error. Translation Error. Error while translating message to native format. Please make sure that the payload for the outbound interaction conforms to the schema. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.
    My input is a File Adpater Read operation and output is File Adapter Write operation.
    The schemas are as below:
    Input schema:
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    xmlns:tns="http://stmatthews.hospital.com/ReadFileDoctorsAppointmentRequest"
    targetNamespace="http://stmatthews.hospital.com/ReadFileDoctorsAppointmentRequest"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    nxsd:version="NXSD"
    nxsd:stream="chars"
    nxsd:encoding="US-ASCII"
    <xsd:element name="doctorAppointmentRequestRoot"><xsd:complexType>
    <xsd:sequence>
    <xsd:element name="doctorAppointmentRequest" minOccurs="1" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="C1" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C2" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C3" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C4" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C5" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C6" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C7" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C8" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C9" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C10" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C11" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C12" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C13" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C14" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C15" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;" />
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    Output Schema:
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    xmlns:tns="http://stmatthews.hospital.com/LogDoctorAppointmentRequests"
    targetNamespace="http://stmatthews.hospital.com/LogDoctorAppointmentRequests"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    nxsd:version="NXSD"
    nxsd:stream="chars"
    nxsd:encoding="US-ASCII"
    <xsd:element name="AppointmentRequestsLog"><xsd:complexType>
    <xsd:sequence>
    <xsd:element name="AppointmentRequest" minOccurs="1" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="C1" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C2" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C4" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C5" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C6" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C7" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C8" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
    <xsd:element name="C9" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy="&quot;" />
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    <!--NXSDWIZ:C:\SOAHandbook\DoctorsAppointmentRequestProcessor\DoctorAppointmentRequestProcessor\samples\Logged_DoctorsAppointmentRequestFile.txt:-->
    <!--USE-HEADER:false:-->
    Transformation XSL used in Mediator:
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0"
    xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/file/DoctorsAppointmentRequestProcessor/DoctorAppointmentRequestProcessor/ReadFileDoctorsAppointmentRequest"
    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:pc="http://xmlns.oracle.com/pcbpel/"
    xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
    xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:ora="http://schemas.oracle.com/xpath/extension"
    xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
    xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
    xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
    xmlns:imp1="http://stmatthews.hospital.com/ReadFileDoctorsAppointmentRequest"
    xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
    xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
    xmlns:med="http://schemas.oracle.com/mediator/xpath"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/"
    xmlns:ns1="http://stmatthews.hospital.com/LogDoctorAppointmentRequests"
    xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
    xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
    xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:bpmn="http://schemas.oracle.com/bpm/xpath"
    xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/file/DoctorsAppointmentRequestProcessor/DoctorAppointmentRequestProcessor/LogDoctorAppointmentRequests"
    xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
    exclude-result-prefixes="xsi xsl tns pc plt wsdl imp1 jca xsd ns1 ns0 xp20 bpws bpel bpm ora socket mhdr oraext dvm hwf med ids xdk xref bpmn ldap">
    <xsl:template match="/">
    <ns1:AppointmentRequestsLog>
    <ns1:AppointmentRequest>
    <ns1:C1>
    <xsl:value-of select="xp20:current-date()"/>
    </ns1:C1>
    <ns1:C2>
    <xsl:value-of select='substring-before("doctor1234_20120926_helloworld","_")'/>
    </ns1:C2>
    <ns1:C4>
    <xsl:value-of select="concat(/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C2,/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C3)"/>
    </ns1:C4>
    <ns1:C5>
    <xsl:value-of select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C4"/>
    </ns1:C5>
    <ns1:C6>
    <xsl:value-of select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C5"/>
    </ns1:C6>
    <ns1:C7>
    <xsl:value-of select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C12"/>
    </ns1:C7>
    <ns1:C8>
    <xsl:value-of select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C14"/>
    </ns1:C8>
    <ns1:C9>
    <xsl:value-of select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C15"/>
    </ns1:C9>
    </ns1:AppointmentRequest>
    </ns1:AppointmentRequestsLog>
    </xsl:template>
    </xsl:stylesheet>
    Just in case if you are aware, Im trying the example in Lucas Jellema's book Chapter 7 and Im getting the error there in the first example project.
    I have seen few very old threads on this problem in the forum but none of them had any answers so opening up a new one.
    Thanks.

    Your transformation with for-each look is incorrect.
    This is what you have right now:
    <ns1:AppointmentRequestsLog>
    <xsl:for-each select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest">
    <ns1:AppointmentRequest>
    <ns1:C1>
    <xsl:value-of select="xp20:current-date()"/>
    </ns1:C1>
    <ns1:C2>
    <xsl:value-of select='substring-before("doctor1234_20120926_helloworld","_")'/>
    </ns1:C2>
    <ns1:C3>
    <xsl:value-of select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest/imp1:C2"/>
    </ns1:C3>This is the correct way to write for-each within XSLT:
    <ns1:AppointmentRequestsLog>
    <xsl:for-each select="/imp1:doctorAppointmentRequestRoot/imp1:doctorAppointmentRequest">
    <ns1:AppointmentRequest>
    <ns1:C1>
    <xsl:value-of select="xp20:current-date()"/>
    </ns1:C1>
    <ns1:C2>
    <xsl:value-of select='substring-before("doctor1234_20120926_helloworld","_")'/>
    </ns1:C2>
    <ns1:C3>
    <xsl:value-of select="imp1:C2"/>
    </ns1:C3>Also, check the flow trace in the EM console for the instance which errored out and paste here the data which is being sent to the FileWrite Adapter. Also, you need to ensure that any elements which are defined as xs:int should not have empty string as values. For example in your write schema C3 has int. So you should map C3 in XSLT like following:
    <xsl:choose>
    <xsl:when test="imp1:C2 and string-length(imp1:C2) > 0">
    <ns1:C3>
    <xsl:value-of select="imp1:C2"/>
    </ns1:C3>
    </xsl:when>
    <xsl:otherwise>
    <ns1:C3>0</ns1:C3>
    </xsl:otherwise>
    </xsl:choose>

  • Remove ?xml version="1.0" encoding="UTF-8"? from xml file

    I have generated an XML file using sax paraser. In the XML file thats generated I have the version and the encoding line
    <?xml version="1.0" encoding="UTF-8"?>which is automatically generated in my XML file. Is there any way that I can avoid that from the XML file thats generated.

      try
                            FileWriter fr = new FileWriter(new File(path, fileName));
                            Document docNode = docNodeMap.get(name);
                            XMLOutputter outputter = new XMLOutputter();
                            outputter.output(docNode, fr);
                            fr.close();
                    catch (IOException e)
                            e.printStackTrace();
                    }this the code generating xml file.

  • Remove ?xml version="1.0" encoding="UTF-8"?   from XML doc

    I have generated an XML file using javax XML transformer. In the XML file thats generated I have the version and the encoding line
    <?xml version="1.0" encoding="UTF-8"?>
    which is automatically generated in my XML file. Is there any way that I can avoid that from the XML file thats generated.
    Here is the transformer that I have used.
    public static void printToXML(String fileName){
               try{
                    File file = new File(fileName);
                    Transformer tr = TransformerFactory.newInstance().newTransformer();
                    tr.setOutputProperty(OutputKeys.INDENT, "yes");
                    tr.setOutputProperty(OutputKeys.METHOD,"xml");
                    tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
                    tr.transform( new DOMSource(dom),new StreamResult(new FileWriter(file)));
               }catch(TransformerConfigurationException tcex){
                    logger.info("TransformerConfigurationException at printToXML method in CSVtoXML.java");
                    logger.error("TransformerConfigurationException", tcex);
               }catch(TransformerException tex){
                    logger.info("TransformerException at printToXML method in CSVtoXML.java");
                    logger.error("TransformerException", tex);
               }catch(IOException ioex){
                    logger.info("IOException at printToXML method in CSVtoXML.java");
                    logger.error("IOException", ioex);
          }

    Well, it is a pretty important line. Why do you need it removed? Anything that really processes XML knows how to read it and determine what encoding was used. That is vital, if you look at the number of questions posted here about foreign language text in XML. If you really have a text processsor that knows how to open a file called something.xml, and knows how to process or ignore most of the pointy bracket things, but not this one, it is time to fix it.
    Dave Patterson

  • Parsing a UTF-8 encoded XML Blob object

    Hi,
    I am having a really strange problem, I am fetching a database BLOB object containing the XMLs and then parsing the XMLs. The XMLs are having some UTF-8 Encoded characters and when I am reading the XML from the BLOB, these characters lose their encoding, I had tried doing several things, but there is no means I am able to retain their UTF encoding. The characters causing real problem are mainly double qoutes, inverted commas, and apostrophe. I am attaching the piece of code below and you can see certain things I had ended up doing. What else can I try, I am using JAXP parser but I dont think that changing the parser may help because, here I am storing the XML file as I get from the database and on the very first stage it gets corrupted and I have to retain the UTF encoding. I tried to get the encoding info from the xml and it tells me cp1252 encoding, where did this come into picture and I couldn't try it retaining back to UTF -8
    Here in the temp.xml itself gets corrupted. I had spend some 3 days on this issue. Help needed!!!
    ResultSet rs = null;
        Statement stmt = null;
        Connection connection = null;
        InputStream inputStream = null;
        long cifElementId = -1;
        //Blob xmlData = null;
        BLOB xmlData=null;
        String xmlText = null;
        RubricBean rubricBean = null;
        ArrayList arrayBean = new ArrayList();
          rs = stmt.executeQuery(strQuery);
         // Iterate till result set has data
          while (rs.next()) {
            rubricBean = new RubricBean();
            cifElementId = rs.getLong("CIF_ELEMENT_ID");
                    // get xml data which is in Blob format
            xmlData = (oracle.sql.BLOB)rs.getBlob("XML");
            // Read Input stream from blob data
             inputStream =(InputStream)xmlData.getBinaryStream(); 
            // Reading the inputstream of data into an array of bytes.
            byte[] bytes = new byte[(int)xmlData.length()];
             inputStream.read(bytes);  
           // Get the String object from byte array
             xmlText = new String(bytes);
           // xmlText=new String(szTemp.getBytes("UTF-8"));
            //xmlText = convertToUTF(xmlText);
            File file = new File("C:\\temp.xml");
            file.createNewFile();
            // Write to temp file
            java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(file));
            out.write(xmlText);
            out.close();

    What the code you posted is doing:
    // Read Input stream from blob data
    inputStream =(InputStream)xmlData.getBinaryStream();Here you have a stream containing binary octets which encode some text in UTF-8.
    // Reading the inputstream of data into an
    into an array of bytes.
    byte[] bytes = new byte[(int)xmlData.length()];
    inputStream.read(bytes);Here you are reading between zero and xmlData.length() octets into a byte array. read(bytes[]) returns the number of bytes read, which may be less than the size of the array, and you don't check it.
    xmlText = new String(bytes);Here you are creating a string with the data in the byte array, using the platform's default character encoding.
    Since you mention cp1252, I'm guessing your platform is windows
    // xmlText=new new String(szTemp.getBytes("UTF-8"));I don't know what szTemp is, but xmlText = new String(bytes, "UTF-8"); would create a string from the UTF-8 encoded characters; but you don't need to create a string here anyway.
    //xmlText = convertToUTF(xmlText);
    File file = new File("C:\\temp.xml");
    file.createNewFile();
    // Write to temp file
    java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.FileWriter(file));This creates a Writer to write to the file using the platform's default character encoding, ie cp1252.
    out.write(xmlText);This writes the string to out using cp1252.
    So you have created a string treating UTF-8 as cp1252, then written that string to a file as cp1252, which is to be read as UTF-8. So it gets mis-decoded twice.
    As the data is already UTF-8 encoded, and you want the output, just write the binary data to the output file without trying to convert it to a string and then back again:// not tested, as I don't have your Oracle classes
    final InputStream inputStream = new BufferedInputStream((InputStream)xmlData.getBinaryStream());
    final int length = xmlData.length();
    final int BUFFER_SIZE = 1024;                  // these two can be
    final byte[] buffer = new byte[BUFFER_SIZE];   // allocated outside the method
    final OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    for (int count = 0; count < length; ) {
       final int bytesRead = inputStream.read(buffer, 0, Math.min(BUFFER_SIZE, (length - count));
       out.write(buffer, 0, bytesRead);
       count += bytesRead;
    }Pete

  • Reading using UTF-8 coding

    hi
    I am trying to read an Arabic text from textfile and copy it to another file, using UTF-8 coding, I saved the file in UTF-8 conding , but I get a result with strange charachters.
    this is the code
    * @Program that returns a Unicode string.
    * ReadUTF.java
    * Author:-RoseIndia Team
    * Date:-07-jun-2008
    import java.io.*;
    public class ReadUTF {
    public static void readArabic(String filename, String outFile ){
    try{
    File file = new File(filename);
    BufferedReader fileReader = new BufferedReader(new FileReader(file));
    BufferedWriter fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
    String str;
    while ((str = fileReader.readLine()) != null) {
    fileWriter.write(str);
    fileWriter.newLine();
    System.out.println(str);
    fileReader.close();
    fileWriter.flush();
    fileWriter.close();
    catch(IOException e){
    e.printStackTrace();
    public static void main(String[] args)throws IOException {
    readArabic("arabi.txt", "Arabia2.txt");
    } //======================================
    this is what I am sopose 2 get
    HomeNewsSportRadioTVWeatherLanguages
    &#1606;&#1589;&#1608;&#1589; &#1601;&#1602;&#1591;
    &#1570;&#1582;&#1585; &#1578;&#1581;&#1583;&#1610;&#1579;: &#1575;&#1604;&#1571;&#1585;&#1576;&#1593;&#1575;&#1569; 15 &#1571;&#1603;&#1578;&#1608;&#1576;&#1585; 2008 09:24 GMT
    &#1571;&#1581;&#1583;&#1579; &#1575;&#1604;&#1571;&#1582;&#1576;&#1575;&#1585;
    &#1608;&#1575;&#1588;&#1606;&#1591;&#1606; &#1608;&#1575;&#1579;&#1602;&#1577; &#1605;&#1606; &#1575;&#1604;&#1578;&#1608;&#1589;&#1604; &#1604;&#1575;&#1578;&#1601;&#1575;&#1602; &#1571;&#1605;&#1606;&#1610; &#1605;&#1593; &#1575;&#1604;&#1593;&#1585;&#1575;&#1602;
    &#1593;&#1580;&#1586; &#1575;&#1604;&#1605;&#1610;&#1586;&#1575;&#1606;&#1610;&#1577; &#1575;&#1604;&#1571;&#1605;&#1585;&#1610;&#1603;&#1610;&#1577; &#1578;&#1590;&#1575;&#1593;&#1601; &#1579;&#1604;&#1575;&#1579; &#1605;&#1585;&#1575;&#1578;
    &#1602;&#1605;&#1577; &#1576;&#1585;&#1608;&#1603;&#1587;&#1604; &#1575;&#1604;&#1571;&#1608;&#1585;&#1608;&#1576;&#1610;&#1577; &#1578;&#1576;&#1581;&#1579; &#1575;&#1604;&#1571;&#1586;&#1605;&#1577; &#1575;&#1604;&#1605;&#1575;&#1604;&#1610;&#1577;
    &#1587;&#1608;&#1585;&#1610;&#1577; &#1608;&#1604;&#1576;&#1606;&#1575;&#1606; &#1610;&#1593;&#1604;&#1606;&#1575;&#1606; &#1585;&#1587;&#1605;&#1610;&#1575; &#1576;&#1583;&#1569; &#1575;&#1604;&#1593;&#1604;&#1575;&#1602;&#1575;&#1578; &#1575;&#1604;&#1583;&#1576;&#1604;&#1608;&#1605;&#1575;&#1587;&#1610;&#1577;
    &#1608;&#1586;&#1610;&#1585; &#1575;&#1604;&#1582;&#1575;&#1585;&#1580;&#1610;&#1577; &#1575;&#1604;&#1604;&#1576;&#1606;&#1575;&#1606;&#1610; &#1608;&#1606;&#1592;&#1610;&#1585;&#1607; &#1604;&#1587;&#1608;&#1585;&#1610; &#1610;&#1608;&#1602;&#1593;&#1575;&#1606; &#1601;&#1610; &#1583;&#1605;&#1588;&#1602; &#1593;&#1604;&#1609; &#1576;&#1610;&#1575;&#1606; &#1610;&#1593;&#1604;&#1606; &#1576;&#1583;&#1569; &#1575;&#1604;&#1593;&#1604;&#1575;&#1602;&#1575;&#1578; &#1575;&#1604;&#1583;&#1576;&#1604;&#1608;&#1605;&#1575;&#1587;&#1610;&#1577; &#1576;&#1610;&#1606; &#1587;&#1608;&#1585;&#1610;&#1577; &#1608;&#1604;&#1576;&#1606;&#1575;&#1606; &#1575;&#1593;&#1578;&#1576;&#1575;&#1585;&#1575; &#1605;&#1606; &#1575;&#1604;&#1610;&#1608;&#1605;.
    &#1575;&#1578;&#1601;&#1575;&#1602; &#1587;&#1608;&#1585;&#1610; &#1604;&#1576;&#1606;&#1575;&#1606;&#1610; &#1593;&#1604;&#1609; &#1578;&#1585;&#1587;&#1610;&#1605; &#1575;&#1604;&#1581;&#1583;&#1608;&#1583;
    &#1578;&#1593;&#1604;&#1610;&#1602;&#1575;&#1578;&#1603;&#1605;: &#1587;&#1608;&#1585;&#1610;&#1577; &#1578;&#1602;&#1610;&#1605; &#1593;&#1604;&#1575;&#1602;&#1575;&#1578; &#1583;&#1576;&#1604;&#1608;&#1605;&#1575;&#1587;&#1610;&#1577; &#1605;&#1593; &#1604;&#1576;&#1606;&#1575;&#1606;
    //==============================
    and here What the compiler gives me
    HomeNewsSportRadioTVWeatherLanguages
    ?ص?ص ??ط
    آخر ت*د?ث: ا?أربعاء 15 أ?ت?بر 2008 09:24 GMT
    أ*دث ا?أخبار
    ?اش?ط? ?اث?ة ?? ا?ت?ص? ?ات?ا? أ??? ?ع ا?عرا?
    عجز ا???زا??ة ا?أ?ر???ة تضاع? ث?اث ?رات
    ??ة بر??س? ا?أ?ر?ب?ة تب*ث ا?أز?ة ا??ا??ة
    س?ر?ة ??ب?ا? ?ع??ا? رس??ا بدء ا?ع?ا?ات ا?دب???اس?ة
    ?ز?ر ا?خارج?ة ا??ب?ا?? ??ظ?ر? ?س?ر? ???عا? ?? د?ش? ع?? ب?ا? ?ع?? بدء ا?ع?ا?ات ا?دب???اس?ة ب?? س?ر?ة ??ب?ا? اعتبارا ?? ا????.
    ات?ا? س?ر? ?ب?ا?? ع?? ترس?? ا?*د?د
    تع???ات??: س?ر?ة ت??? ع?ا?ات دب???اس?ة ?ع ?ب?ا?
    Can anyone please figure out what is the problem ?

    j2ee_ubuntu wrote:
    //BufferedReader fileReader = new BufferedReader(new FileReader(file)); //replace this with given below
    BufferedReader fileReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
    Nice spoon-feeding there. I assure you that the OP has learned exactly nothing now.

  • UTF-16 and file names

    Hi,
    On Windows (2K & XP atleast) you can have file names containing characters that are represented using UTF-16. E.g. The unicode character \ubf3f (decimal equivalent 48959). Below is a snippet of code that attempts to create a file containing this character.
    File f = new File ("c:/temp", "\ubf3f.txt");
    FileWriter w = new FileWriter(f);
    w.write("a");
    w.close();
    And the result is the following:
    java.io.FileNotFoundException: d:\temp\?.txt (The filename, directory name, or volume label syntax is incorrect)
         at java.io.FileOutputStream.open(Native Method)
         at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
         at java.io.FileOutputStream.<init>(FileOutputStream.java:57)
         at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
         at java.io.FileWriter.<init>(FileWriter.java:58)
    Clearly java is unable to interpret the file name. So I created the file on windows directly and it was fine. Then I tried to do a file.exists() test and it returned false. So either ways, I'm unable to work with this file in java.
    Appreciate if some one can throw some light on why this is happening and what needs to be done to solve it.
    Pradeep

    Forgot to mention that the java version is 1.3.1_03-b03. Before posting I searched the bug database but couldn't find something that was related. If some one finds it, please do post the bug number.
    Thanks,
    Pradeep

  • Invalid byte 1 of 1-byte UTF-8 sequence

    Hello all,
    I get an xml string say (xmlString)from a SQL server DB, to which I do
    1)
    byte[] barray = xmlResults.getBytes("UTF8");
    xmlResults = new String(barray, "UTF8");
    2)
    xmlresults = <?xml version=\"1.0\" encoding=\"UTF-8\"?><reports>" + xmlResults + "</reports>
    3)Then write the string contents to a file
    FileWriter fw = new FileWriter("C:\\Tomcat 4.1\\webapps\\alertLine\\DataExtraction\\xml\\" + test.xml,true);
    System.out.println("filewriter encoding: " + fw.getEncoding());
    //output---filewriter encoding: Cp1252
    PrintWriter outl = new PrintWriter(new BufferedWriter(fw));
    outl.print(xmlResults);
    4)Then do this...
    InputStream fileStream = null;
    try {
    fileStream = new FileInputStream(xmlBase + text.xml);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    InputSource inputSource = new InputSource(fileStream);
    DOMParser parser = new DOMParser();
    inputSource.setEncoding("UTF-8");
    try {
    parser.parse(inputSource);
    } catch (SAXException e) {
    e.printStackTrace();
    The paser.parse(inputSource) throws "java.io.UTFDataFormatException"
    How to fix this? Is this due to the encoding of the fileWriter?If so how can I set the encoding?

    Is this due to the encoding of the fileWriter?Yes, it is.
    If so how can I set the encoding?Short answer:Writer fw = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8");Long answer:
    Leave out step 1, it does nothing but waste time and space. You have a String and the end result is the same String.
    In step 3, don't use the "append" version of the writer. And if you are writing the XML to a file only so you can immediately read it back into your DOMParser, then don't write to a file at all. This is sufficient:InputSource inputSource = new InputSource(new StringReader(xmlresults));
    try {
      parser.parse(inputSource);
    } catch(SAXException e)
      // and so on...

  • Reading a file in UTF-8 format

    Hi,
    I am trying to read a UTF-8 file but cannot see how to tell the file reader ( BufferedREader) to expect a UTF-8 format.
    I can write to a UTF-8 formatted file ok using a Charset object in the FileWriter constructor but I can't see the equivalent solution for reading.
    Any help appreciated
    Thanks ... J

    import java.io.*;
    class Test127 {
        public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, IOException {
            BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream (args[0]), "UTF-8"));
            String line = br.readLine();
            if (line != null)
                System.out.println (line);
            br.close();

  • Como deixar a codificação padrão "iso-8859-1" ao invés de "utf-8" no navegador?

    Quando faço o acesso ao banco do meu cartão de crédito, a primeira pagina deles é codificada com "UTF-8" e também existe o comando "charset=utf-8" no código HTML, após digitar o número do cartão, ele direciona para outra página, porém codificada com "iso-8859-1", mas sem nenhuma codificação no código HTML.
    Identifiquei que o navegador usa por padrão o "utf-8" quando não existe codificação no código HTML, então gostaria de modificar esse padrão para "iso-8859-1".
    O único lugar que encontrei para essa codificação foi ao pressionar o botão de avançado em "Fontes e cores", porém não funcionou.
    A versão do meu navegado é 23.0.1, entretanto desde a versão 18 que encontro esse problema.

    It is possible that the server sends the file(s) by default with UTF-8 and in such a case this encoding send by the server prevails over all other settings.
    You can see the encoding here: Tools > Page Info > General
    *Press the F10 key or tap the Alt key to bring up the hidden "Menu Bar" temporarily.

  • Conversion of XML file from ANSI to UTF-8 encoding in SAP 4.6C

    Hi All,
      Im working on SAP 4.6C version.I have generated a XML file from my custom report.It is downloading in ANSI format.But i need to download this into UTF-8 format.So can anyone please let me know how to do this?
    Is this possible in 4.6C version?
    Thanks in Advance,
    Aruna A N

    Hello
    It is possible in 4.6.
    Try this code:
    REPORT Z_TEST_XML_DOWN .
    data:
      lp_ixml type ref to if_ixml,
      lp_xdoc type ref to if_ixml_document,
      lp_sfac type ref to if_ixml_stream_factory,
      lp_ostr type ref to if_ixml_ostream,
      lp_rend type ref to if_ixml_renderer,
      lp_enco type ref to if_ixml_encoding.
    data:
      lp_root type ref to if_ixml_element,
      lp_coll type ref to if_ixml_element,
      lp_elem type ref to if_ixml_element.
    class cl_ixml definition load.
    data:
    udat like lfa1,
    s type string.
    select single * from lfa1 into udat where lifnr = '0000000001'. " <- set here real number
    *** create xml
    lp_ixml = cl_ixml=>create( ).
    lp_xdoc = lp_ixml->create_document( ).
    lp_root = lp_xdoc->create_simple_element( name = 'Node'
                                              parent = lp_xdoc ).
    s = udat-land1.
    call method lp_root->set_attribute( name = 'country_name'
                                        value = s ).
    s = udat-name1.
    call method lp_root->set_attribute( name = 'vendor_name'
                                        value = s ).
    s = udat-ort01.
    call method lp_root->set_attribute( name = 'city_name'
                                        value = s ).
    *** render xml
    types: begin of xml_tab_line,
             line(256) type x,
           end of xml_tab_line.
    types: xtab type table of xml_tab_line.
    data: t_xml type xtab,
          size type i,
          rc type i.
    lp_sfac = lp_ixml->create_stream_factory( ).
    lp_ostr = lp_sfac->create_ostream_itable( table = t_xml ).
    lp_enco = lp_ixml->create_encoding( character_set = 'utf-8'
                                   byte_order = if_ixml_encoding=>co_none ).
    call method lp_ostr->set_encoding( encoding = lp_enco ).
    lp_rend = lp_ixml->create_renderer( ostream = lp_ostr
                                        document = lp_xdoc ).
    rc = lp_rend->render( ).
    *** export to file
    size = lp_ostr->get_num_written_raw( ).
    call function 'WS_DOWNLOAD'
      exporting
        bin_filesize = size
        filename = 'c:\sapxml_test.xml'
        filetype = 'BIN'
      tables
        data_tab = t_xml
      exceptions
        others = 1.
    It is just simple example.

  • ISO vs UTF-8

    La migración de la BBDD de una aplicación desde un encoding ISO-8859-1 a otra con enconding UTF-8 puede presentar problemas durante el proceso de import debido al tratamiento que el encoding UTF-8 realiza de los campos CHAR, VARCHAR y VARCHAR2.
    El origen de los problemas viene provocado por que en ISO-8859-1 cualquier carácter (normales, acentuados, ñ, etc…) ocupa 1 byte mientras que en UTF-8, los caracteres “especiales” ocupan más de 1 byte.
    Para evitar este problma es necesario especificar los campos CHAR, VARCHAR y VARCHAR2 con el atributo CHAR ya que de esta manera se consigue desligar a los datos del encoding de la BBDD en la que resida. En caso contrario ORACLE asumirá por defecto que el tamaño implica “bytes” y como consecuencia un encoding UTF-8 producirá problemas al manejar caracteres especiales.
    Por otro lado, la realización de este cambio deja en manos de ORACLE la decisión sobre el tamaño físico de datos a emplear de forma que, en el caso que los VARCHAR que no contengan caracteres extraños su tamaño coincidirá exactamente al tamaño en bytes en TS pero, un campo que contenga uno (o más) caracteres especial, verá incrementado el espacio empleado en disco de forma proporcional. En este caso, ORACLE recomienda considerar un incremento de un 15% sobre el espacio de disco ocupado en la versión ISO.
    http://www.fancypeople.org

    Google Translate does it thusly
    >
    The migration of a DB application from an encoding ISO-8859-1 to another with enconding UTF-8 can present problems during the import process due to treatment than UTF-8 encoding performed in the fields CHAR, VARCHAR and VARCHAR2.
    The origin of the problem that is caused by ISO-8859-1 any character (normal, accentuated, ñ, etc ...) while occupies 1 byte in UTF-8 characters "special" occupy more than 1 byte.
    To work around this problme is necessary to specify the fields CHAR, VARCHAR and VARCHAR2 to CHAR attribute as is done this way to separate the data encoding of the DB where you live. Otherwise default ORACLE assume that the mean size "bytes" and result in UTF-8 encoding will cause problems when handling special characters.
    Furthermore, the implementation of this change ORACLE leaves the decision on the physical size of data to be used so that, for the VARCHAR containing no strange characters will match exactly the size in bytes in size but TS A field containing one (or more) special characters, will increase the disk space used proportionately. In this case, Oracle recommends considering an increase of 15% of the disk space occupied in the ISO version.
    >
    I do not see a question or issue in there :-)
    Srini

  • Error 1030723 Unable to get UTF-8 locale when using Essbase API 11.1.1

    Now I got a question about how to connect to an Essbase Server by using essbase client API (11.1.1). I encountered an error “Unable to get UTF-8 locale” when I tried to EssInit((pInitStruct, phInstance) API.
    However, I had no problem to call the API if I uses essbase previous client APIs (7.1 or 9.3).
    I passed the “ESS_API_UTF8” to usApiType field in the ESS_INIT_T struct. When I openned the “essapi.h” header file, I found these are some new fields (highlighted in red color below) added in the essbase client API (11.1.1)
    ESS_TSA_API_typedef_struct(ess_init_t)
    ESS_TSA_ELEMENT(ESS_ULONG_T, Version); /* This should be set to ESS_API_VERSION */
    ESS_TSA_ELEMENT(ESS_PVOID_T, UserContext); /* void pointer to user's message context */
    ESS_TSA_ELEMENT(ESS_USHORT_T, MaxHandles); /* max number of context handles required */
    ESS_TSA_ELEMENT(ESS_SIZE_T, MaxBuffer); /* max size of buffer that can be allocated */
    ESS_TSA_ELEMENT(ESS_STR_T, LocalPath); /* local path to use for file operations */
    ESS_TSA_ELEMENT(ESS_STR_T, MessageFile); /* full path name of message database file */
    ESS_TSA_ELEMENT(ESS_PFUNC_T, AllocFunc); /* user-defined memory allocation function */
    ESS_TSA_ELEMENT(ESS_PFUNC_T, ReallocFunc); /* user-defined memory reallocation function */
    ESS_TSA_ELEMENT(ESS_PFUNC_T, FreeFunc); /* user-defined memory free function */
    ESS_TSA_ELEMENT(ESS_PFUNC_T, MessageFunc); /* user-defined message callback function */
    ESS_TSA_ELEMENT(ESS_STR_T, HelpFile); /* user-defined help file path */
    ESS_TSA_ELEMENT(ESS_PVOID_T, Ess_System); /* reserved for internal use */
    ESS_TSA_ELEMENT(ESS_USHORT_T, usApiType);
    ESS_TSA_ELEMENT(ESS_PCATCHFUNC_T, CatchFunc); /* user-defined kill-own-request signal callback function */
    ESS_TSA_ELEMENT(ESS_PCATCH_INIT_FUNC_T, CatchInitFunc); /* user-defined kill-own-request signal initialization callback function */
    ESS_TSA_ELEMENT(ESS_PCATCH_TERM_FUNC_T, CatchTermFunc); /* user-defined kill-own-request signal termination callback function */
    ESS_TSA_ELEMENT(ESS_PCOOKIE_CREATE_FUNC_T, CookieCreateFunc); /* user-defined cookie creation function */
    ESS_TSA_ELEMENT(ESS_PCOOKIE_DELETE_FUNC_T, CookieDeleteFunc); /* user-defined cookie creation function */
    } ESS_TSA_END(ESS_INIT_T);
    I could not find any document to introduce the API (11.1.1. And what does the error “Unable to get UTF-8 locale” mean? How can work around it. Any environment parameters or paths need to be set?
    Please advise.

    Hi,
    The API documentation for V11 is available from :- http://download.oracle.com/docs/cd/E12825_01/epm.111/esb_apiref/frameset.htm?launch.htm
    Hopefully it might point you in the right direction.
    Cheers
    John
    http://john-goodwin.blogspot.com/

Maybe you are looking for

  • Events for changed entry in data dictionary

    Hi , I  have a requirement as mentioned below: my table has four fields : 1. vkorg 2. validity_period 3. modification_date and 4. modification_time. I have to capture the modification date and modification time if a user changes an entry (or entries)

  • Question mark (?) where My Boot Camp Applications used to be

    I have just upgraded to Mountain Lion and therefore needed to upgrade my Parallels to version 7.  However on the upgrade to Mountain Lion, the My Boot Applications Folder became a question mark (?) and I was prompted to upgrade to Parallels 7 which I

  • Exporting pdf in Indesign that allows commenting & saving in Acrobat Reader

    I have a feeling there isn't a way to do this but I thought I would ask in case there is. I was wondering if you can export a pdf in Indesign CS4 that someone who is using Acrobat Reader X can comment and then save. I know you can open the pdf in Acr

  • Unable to process an invoice

    Hi all I am unable to process this invoice due to an error accrued u201CYou cannot post to 73230002 using WBS elementu201D do you know why? Please advice regards

  • How can take a Custom Data Type in TestStand and create a LabVIEW DataType?

    I am using LV 8.2 and TS 3.5. I have an existing Custom Data Type in TestStand and I want to make a LabView Type Def.  The TS DataType contains 11 elements: a Visa Resource Container of 2 elements (String, DeviceName and Number, Session), 9 Numerics