How to identify the encoding used in a file ?

Hi all,
I have to read a file and check it is encoded in UTF-8. How I can do this ?. If fiel is saved in MS Windows I can check for BOM. What if the file is saved using Java API ?. Is there any code(copy left code) available for doing this ?
rgds
Antony Paul

The problem is that ther eare no definite tests for character encoding. A particular byte stream can be valid in any number of different encodings (even if the resulting characters are not correct). If the characters don't happen to include any above unicode 127 then a UTF-8 stream is identical to the same characters in any number of different encodings.
It's not just a matter of there being no code for it in the library, it's impossible to do with any certainty, and to do it even probabalistically you'd have to run the results through a multi-lingual spelling checker.
If you just ask java.io to open a Reader without specifying an encoding it will assume the default encoding of your system.

Similar Messages

  • How to identify the Encoding type in an XML

    Hi all,
    Is it possible to identify the encoding set to and XML programatically?
    for example :
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <student>
    </student>
    in this is it possible to find out the encoding value set (ISO-8859-1) ?
    Thanx in Adv,
    Potluri

    Hi, if you have a parser that is only DOM level 2 compliant then there is no way to get at the xml declaration via the JAXP and org.w3c.dom apis. It is expected that DOM level 3 will have the functionality in the Document interface to access the xml declaration attributes like the encoding. I don't know if there are any DOM level 3 parsers available, check xml.apache.org to look at the xerces parsers. However as xml files are text files you could right a program using java.io package to look for the <?xml version ...> tag and then to search that line for the encoding.
    Hope this helps.

  • How to get the encoding of a XML file ...

    Hi,
    How do you get the encoding of a XML file?
    For example,
    <?xml version="1.0" encoding="SJIS"?>
    I am trying to retrieve the above encoding="SJIS", but I can't seem to locate the API for doing so.
    Thanks in advance for any help,
    Eric

    Hi ddossot,
    Thanks for your suggestion.
    However, the xerces.jar file that comes with my old tomcat server is an old version and thus, the getEncoding method is not even present in the DocumentImpl class. The option to update to a newer version of tomcat and xerces is not available. What a pity... :-(
    Well, I just have to try to find a way around. Worst case scenario, parse the first line in the xml file myself.
    Regards,
    Eric

  • How to get the "encoding" of a XML file using JDOM

    As in XML file, <?xml version="1.0" encoding="UTF-8" ?> indicates the encoding of this file
    while using JDOM to parse a XML file, how can I get the encoding type?
    thanx!!!

    What my program do is to get the encoding of XML files and convert them to UTF-8 encoding files, while I need this "encoding" information of the original XML document thus I can convert...
    After reading specifications and JDOM docs, the truth turns to be disappointed, no function is provided to get this information in JDOM level 2(the current released one), while it's promissed that this function will be provided in JDOM level API....
    Thanx all for your help and attention!!!

  • How to identify the dtp used in the process chain in bi 7?

    Hi all,
    I have a a couple of dtp in the production system, i need to find out what are all the process chains using this DTP?
    Can anyone help me on this!!
    thanks

    Right click on DTP - If 'process chain' option is enabled for navigation it means it's already used by Process chain - click on it will take you to PC
    If it's disabled then It's not locked in any PC

  • How to reference the properties used in different file in ant

    Hello,
    in my build.xml :
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="name of project" basedir=".">
         <property file="build.properties"/>
    <target name="all" depends="clean,compile"
    description="Clean build and then compile">
    <jar jarfile="${zkintranet.home}/WebContent/WEB-INF/lib/${app.molotto}.jar">
    <fileset dir="${molotto.build.home}/classes"/>
    </jar>
    </target
    </project>
    and in my build.properties
    <project name="common properies" basedir=".">     
                   <property name="app.molotto" value="Missouri Lottery"/>
    </project>
    When I run my ant gives an error ${app.molotto} doesn't not exist !

    what I am trying to achieve is not to repeat the common code
    Basically I can use the loaded.properities (where common code is there) and reference this file in my build.xml and buildAPP.xml without repeating the common code.
    Edited by: cookjava on Jan 23, 2009 9:50 AM

  • How to identify the original source folder of files in the trash?

    I am trying to help a friend who trashed a massive amount of files. Dragging files out of the trash to where they originated from works when one knows where files in the trash came from. What I need to know is how to find out which folder the files originated from. Pictures from iPhoto library, easy ... but there are others that are a mystery.
    Any help is appreciated.
    She is using a macbook running Leopard.

    The only way anyone here could possibly tell where files came from would first have a list of the files with the exact file names. The files themselves don’t carry information of any previous paths, that I know of.
    With the photos, as you said, easy. If they are applications, again, easy, Applications folder. But if they are System files, those can be scattered all over.
    You said it is a massive number of files, so unless the vast majority are photos or applications, it would probably not be practical to make a list.

  • Urgent!!!!!!! How to run the application using webui,server files in Jdev

    Hi All,
    I have bit knowledge on OAF
    I have webui,server files which I took from Server
    Now I want to run this application thru Jdeveloper
    How can I do it?
    Please any help would be greatly appreciated
    Best Regards
    HHH

    As told numerous times on this forum, personilization values only affect if at coding level that property is not set, if in controller code initial value property has already been set, then it will take over your personilzation properties. So better check and confirm this!
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can identify the default currency for a customer?

    How can identify the default currency for a customer?
    I know that this is being determined when you create a sales order for a particular customer, for example, so I could break this process open and find out what it uses. But I thought it worth asking in this forum first.
    Blue

    Hi Gary,
    As per my understanding of your question I am replying , If you are looking some thing else then I request you to please elaborate your query.
    If you see the BP sales area data in transaction BP, In billing tab you maintain the currency for a customer which is default currency when you create a sales order.
    <b>Reward points if it helps!!</b>
    Best regards,
    Vikash

  • Numbers to CSV export script: how to specify the encoding?

    Hi,
    I'm using the following script to export a Numbers document to CSV:
    # Command-line tool to convert an iWork '09 Numbers
    # document to CSV.
    # Parameters:
    # - input: Numbers input file
    # - output: CSV output file
    # Attik System, Philippe Lang
    # Creation date: 31 mai 2012
    # Modification date:
    on run argv
      # We retreive the path of the script
              set myPath to (path to me)
              tell application "Finder" to set myFolder to folder of myPath
      # We get the command line parameters
              set input_file to item 1 of argv
              set output_file to item 2 of argv
      # We retreive the extension of the file
              set theInfo to (info for (input_file))
              set extname to name extension of (theInfo)
      # Paths
              set input_file_path to (myFolder as text) & input_file
              set output_file_path to (myFolder as text) & output_file
              if extname is equal to "numbers" then
        tell application "Numbers"
          open input_file_path
          save document 1 as "LSDocumentTypeCSV" in output_file_path
          close every window saving no
        end tell
              end if
    end run
    It works fine, except that I don't know how to specify the encoding of the text in the CSV file (Latin1, MacRoman, Unicode). This option is available in the export dialog of Numbers. Any hint on how to do that is welcome. (GUI Scripting?)
    Where can I find documentation on the iWork "vocabulary" available? Is there a definitive documentation somewhere? I tried to record an manual export in the script editor, without success. Script is more or less empty.
    Thanks!
    Philippe Lang

    A further note from Yvan. He's made some revisions to the script sent earlier.
    --{code}
    --[SCRIPT export to CSV with selected encoding]
    I added some features.
    (1) Defining the encoding thru the preferences file apply only if
    the application is not in use because the file is read only once in a session.
    A test urge you to quit Numbers if it is running.
    (2) info for is deprecated so it may be removed by Apple tomorrow.
    I no longer use it.
    (3) just for the fun, I added a piece of code allowing you to select the encoding on the fly.
    Thanks to the property chooseEncodingInScript, at this time the script use Unicode (UTF-8)
    (4) I'm wondering which tool is used to launch this script,
    I don't know the way to pass arguments when I run one.
    Yvan KOENIG (VALLAURIS, France)
    2012/06/13
    property chooseEncodingInScript : false
    true = the script will ask you to select the encoding
    false = the script use the embedded encoding
    on run argv
      set input_file to (item 1 of argv) as text
      set output_file to (item 2 of argv) as text
      set myPath to (path to me) as text
              tell application "System Events"
      set theProcesses to name of every application process
      set myFolder to path of container of (disk item myPath)
      set input_file_path to myFolder & input_file
      set output_file_path to myFolder & output_file
      set extname to name extension of (disk item input_file)
      end tell
              if extname is "numbers" then
                        if "Numbers" is in theProcesses then error "Please, quit “Numbers” before running this script !"
      if chooseEncodingInScript then
                                  set theList to {"Mac OS Roman", "Unicode (UTF-8)", "Windows Latin 1"}
                                  set maybe to choose from list theList with prompt "Choose the default encoding applying to export as CSV"
      if maybe is false then
      error number -128
      else if item 1 of maybe is item 1 of theList then
                                            30 -- Mac OS Roman
      else if item 1 of maybe is item 2 of theList then
                                            4 -- Unicode (UTF-8)
      else
                                            12 -- Windows Latin 1
      end if
      else
                                  4 -- Unicode (UTF-8)
      end if
                        do shell script "defaults write com.apple.iWork.Numbers CSVExportEncoding  -int " & result
      tell application "Numbers"
      open input_file_path
                                  save document 1 as "LSDocumentTypeCSV" in output_file_path
      close every window saving no
      end tell
      end if
    end run
    --{code}
    Regards,
    Barry

  • How to identify the type of pocketpc barcode scanner?

    How to identify the type of pocketpc barcode scanner whteher it is intermec or symbol?
    GS

    Hi,
    well, this is the brand of the PDA - the Scanner itself is build into the device. So if you have an intermec device - you have an intermec scanner and vice versa. It is not recommended to use a HP device for example with an external scanner. This scenario is not really supported by the MI setup guides.
    Hope that helps!
    Regards,
    Oliver

  • How to Identify the Type of Font Names in Illustrator

    How to identify the type of font names like "True Type font" (or) "open Type font" for illustrator file using Scripts or any language. Could you please advice me.
    Thanks,
    Prabudass

    If there is an Illustrator SDKor Illustrator Scripting forum, try
    that. ATM won't really help - it is obsolete and should not be
    installed (breaks things).
    Aandi Inston

  • How to identify the type of Fonts

    How to identify the type of font names like "True Type font" (or) "open Type font" for illustrator file using Scripts. Could you please advice me.
    Thanks,
    Prabudass

    The code below will prompt the user with the type face of a single text-frame.
    shastafir
    // 5/4/2009
    // Open a new document and create a single text box
    // with some type in it.
    // Get access to the active layer
    var aiDocument = app.activeDocument;
    var aiLayer = aiDocument.activeLayer;
    // Get access to the type-frame's font
    var textBox = aiLayer.textFrames[0];
    var theFont =
    textBox.textRange.characterAttributes.textFont;
    // Alert user with the name of the font
    alert(theFont.name);

  • How to identify the text color in a word doc.?

    how to identify the text color in a word doc.?
    I need to read a word document using java code. which contains many strings with different colors.
    i need to identify the color and giving the marks accordingly like
    test in blue color so
    test marks=2
    how can i do this using java. i only want to know how can i identify the text color using java code.?

    morgalr wrote:
    I guarantee it is not pretty.Indeed.
    I created a Word doc that simply has the word "Blue" in blue, then a space, then the word "Red" in red, all in the default font that Word started with (Times New Roman). The resulting document is 24,064 bytes. It starts off with 80 bytes of various hex values, mostly 0x00.Then 432 bytes of just 0xFF. Then 2048 bytes of various hex values, mostly 0x00. Then the text "Blue Red" (which appears twice more in the file). And so on...
    Edited by: jverd on May 10, 2010 8:45 AM

  • How to identify the variable processing type

    Hi Experts,
    How to find the details of the variable whether it is filling with user exit or replacement path
    Say i have a variable xxx , how to identify the above details.
    Thanks,

    use RSZGLOBV table in VNAM give your variable and VPROCTP will give you processing type

Maybe you are looking for

  • Best disk maintenance utility

    Is there a 'best' disk utility program that cleans up the disk of unnecessary files, etc? I am not 'strong' computer user so need something that is pretty user friendly and intuitive to use. Thank You...

  • Problem transferring folder info to hard drives.

    I have three Lacie Porche drives 250 Gb. I am having trouble transfering data back and forth between them and my g5 tower. I keep gettng "The Finder cannot complete the operation because some data in "dsc0937.jpg" could not be written. (Error code -3

  • The b to /b text

    I have got the text after parsing a page, but as according to regular expressions, which I used, the extracted lines contain tags like <b> and </b>, at the starting and at the end. Now it should be obviously very easy, if I have to just strip of the

  • Cannot Create Delivery

    Hi, I have created A/R Sales Order for 45 items. All those Items are committed in the stock. Now base on that Sales Order number, when I create delivery I get following error message. "Found Error, code = -5002, msg= Target Item number does not match

  • Using FS with GUI_DOWNLOAD

    Hi I am trying search whether I can pass dynamically created internal table with the method CALL METHOD cl_alv_table_create=>create_dynamic_table       EXPORTING           it_fieldcatalog           = fieldcatalog       IMPORTING           ep_table