How to parse a file ?

I would like to know how could I get information from a file. This file contains picture names and vectors which characterize this picture. For each picture, there is a line with the the following syntax :
[filename] [1st Number of the Vector] [2nd Number of the Vector] [3rd Number of the Vector] ...
What is the best solution to get the all information ?
Thanks for your help
Guillaume

Hi,
are the [ ] part of the file?- Anyway, read in the file line by line and get the parts of it using a StringTokenizer. The following method will write them to a Vector:
public Vector getLineContents(String line) {
Vector v = new Vector(2,2);
StringTokenizer st = new StringTokenizer(line," []");// without [] if they are not part of the format
while (st.hasMoreTokens()) v.add(st.nextToken());
return v;
}// end of methodthis will give you a Vector, where each element is a string, that contains a part of that line. You did not say, which number format is used there, so I could not implement the correct parsing for it - but that is also done within 3 lines of code.
greetings Marsian

Similar Messages

  • How to parse json files

    Hi
    Can anyone help with some In depth tutorials on how to parse json files locally (in the project folder) and online (webservice) in WP8 development
    Thank you in advance
    Jayjay john

    1. Build up a strong type class for this json
    Visual Studio 2013 Hidden Gem: Paste JSON or XML as C# Classes
    2. use Json.Net to Deserialize , like:
    var result = Newtonsoft.Json.JsonConvert.DeserializeObject<yourdatatype>(jsonstring);
    Working with JSON in C#
    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

  • How to parse xml file

    Hi,
    I am having an XML file which is having set of repeated tags like
    <gender>
    <male>
    <name>sk</name>
    <age>19</age>
    </male>
    <male>
    <name>raj</name>
    <age>20</age>
    </male>
    <male>
    <name>kris</name>
    <age>18</age>
    </male>
    </gender>
    Like this i am having the xml file, i have to read the values from this xml file, here we are having male tag is repeated, from this i have to take the name, and age values. can you tell me how to take these values. If you are having the sample send me.
    Thanks,

    Hai
    It may be a bit late to reply but i hope this code will help you
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import java.io.*;
    import java.io.File;
    import org.w3c.dom.*;
    class DomParse
         public void func()
              try               
                   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();               
                   DocumentBuilder db = dbf.newDocumentBuilder();               
                   //File f =new File("trial.xml");
                   Document doc = db.parse(new File("trial.xml")); //your xml file name here
                   //Document doc = db.parse(f);
                   NodeList nl1 = doc.getElementsByTagName("male");
                   for(int i=0;i<nl1.getLength();i++)
                        Node nd = nl1.item(i);
                        NodeList tmplist = nd.getChildNodes();
                        for(int j=0;j<tmplist.getLength();j++)
                             Node tmpNode = tmplist.item(j);
                             String locStr = tmpNode.getTextContent();
                             System.out.println(""+tmpNode.getTextContent());
              catch(Exception e)
                   System.out.println("Error: "+e);
                   e.printStackTrace();
         public static void main(String[] args) //throws
              new DomParse().func();
    with regards
    shan

  • How to parse XML file with namesapce?

    Hi,
       I am trying to parse an xml file having namespace. But no data is returned.
    Sample Code:
    public class XMLFileLoader
    var xml:XML = new XML();
    var myXML:XML = new XML();
    var XML_URL:String = "file:///C:/Documents and Settings/Administrator/Desktop/MyData.xml";
    var myLoader:URLLoader = null;
    public function XMLFileLoader()
    var myXMLURL:URLRequest = new URLRequest(XML_URL);
    myLoader= new URLLoader(myXMLURL);
    myLoader.addEventListener(Event.COMPLETE,download);
    public function download(event:Event):void
    myXML = XML(myLoader.data);
    var ns:Namespace=myXML.namespace("xsi");
    for(var prop:String in myXML)
         trace(prop);
    //Alert.show(myXML..Parameters);
    //trace("Data loadedww."+myXML.toString());
    //Alert.show(myXML.DocumentInfo.attributes()+"test","Message");
    The XML Contains the following format.
    <Network xmlns="http://www.test.com/2005/test/omc/conf"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.test.com/2005/test/omc/conf/TestConfigurationEdition3proposal4.xsd">
        <TestDomain>
          <WAC>
            <!--Release Parameter  -->
            <Parameters ParameterName="ne_release" OutageType="None"
                        accessRight="CreateOnly" isMandatory="true"
                        Planned="false"
                        Reference="true" Working="true">
              <DataType>
                <StringType/>
              </DataType>
              <GUIInfo graphicalName="Release"
                       tabName="All"
                       description="Describes the release version of the managed object"/>
            </Parameters>
    </TestDomain>
    </Network>
    Any sample code how to parse this kind of xml file with namespaces...
    Regards,
    Purushotham

    i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
    i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
    screenshot

  • How to parse xml file, containing image,  generaged from JAX-RS connector?

    Hi,
    We are using JAX-RS connector and just want to call getBusinessObjects() directly using JerseyMe (basically bypassing sync engine). We have used sync engine so far and want to try as how to bypass it. The method produces the text/xml and verified the xml file in the web by giving the full url. The plan is to call the same URL from the Java Me Client using JerseyMe. When I print the bytes at the client I receive the same xml that I have seen in the web. Actually, I am passing an image that I can see in a different character format in xml (assuming this is bcos of UTF-8 encoding). I am wondering as how to parse this xml file and how to decode the "UTF-8" format? Do we need to use SGMP for this or use kxml or java me webservices spec.
    I would really appreciate if somebody can answer this one.
    I have been observing in this forum that SGMP team is not at all active in answering the questions. Please let us know whether Oracle is keeping this product and we can continue using SGMP1.1. Please let us know so that we can plan accordingly as we are building a product based on SGMP.

    Hi Rajiv,
    The client library is using org.apache.commons.codec.binary.Base64 internally. We don't have the full Commons Codec library bundled, but you can look up the javadoc for the Base64 class online. All you need to do is call Base64.decode(obj.getBytes()) on the objects you get out of the XML.
    In general it isn't a good idea to depend on implementation details of the client library, but in this case, I think it is pretty safe to expect org.apache.commons.codec.binary.Base64 to remain in our library.
    --Ryan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to parse XML files from normal FTP Servers?

    I want to parse xml files from a normal FTP Servers , NOT the sap application severs itself. How can i do that?
    I know how to use the SAPFTP getting and putting files ,but I don't want to download and then parse it.
    Who knows how to parse it directly? I Just need to read the contents into a database.
    Thanks.

    I want to parse xml files from a normal FTP Servers , NOT the sap application severs itself. How can i do that?
    I know how to use the SAPFTP getting and putting files ,but I don't want to download and then parse it.
    Who knows how to parse it directly? I Just need to read the contents into a database.
    Thanks.

  • How to parse xml file in midlet

    Hi Guys,
    i wish to parse xml file and display it in my midlet. i found api's supporting xml parsing in j2se ie., in java.net or j2se 5.0. Can u please help me what package to use in midlet?
    how to parse xml info and display in midlet? Plz reply soon......Thanks in advance....

    i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
    i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
    screenshot

  • How to parse binary files

    Hi All,
    I have one binary file (abc.dat) file I want to parse that file and need it in text format.
    Can anyone tell me how can I achieve that? is there any third party tools available?
    lines are like below:
    00000000h: 76 04 00 01 00 FF 0F 11 FF 09 07 03 15 ; v....
    can anyone have idea how can i resolve this?
    Thanks!!!

    Hi
    thanks for reply...
    actually what I want is a line that I have posted in first conversation the whole file has lines like that. Now, I want to convert that file in to text format.
    right now I am reading lines with the below code...
    try{
                   FileInputStream fstream = new FileInputStream("test.dat");
                   DataInputStream in = new DataInputStream(fstream);
                   BufferedReader br = new BufferedReader(new InputStreamReader(in));
                   //BufferedInputStream bufferedInputStream = new BufferedInputStream(in);
                   String strLine;
    //               Read File Line By Line
                   while ((strLine = br.readLine()) != null) {
    //                Print the content on the console
                   System.out.println (strLine);
    //               Close the input stream
                   in.close();
                   }catch (Exception e){//Catch exception if any
                   System.err.println("Error: " + e.getMessage());
                   }and I don't get output in the text format.
    So, after doing this can anyone please tell me how can I get decoded format file?
    what are the next steps I should go?
    For, example we can go for (index.dat) file.
    Thanks!!!

  • How to parse text file?

    Hi,
    I would like to read data from a text file that my program has created.
    This is what I have when I create my file:
    try
                   File file = new File("/Users/seifmouelhi/Desktop/Output.txt");
                   FileOutputStream out = new FileOutputStream(file);
                   PrintStream print = new PrintStream(out);
                   System.setOut(print);
              catch(Exception e)
                   System.out.println("set system out failed!!!!!");
                   System.out.println(e.toString());
                   System.exit(0);
    and what can I use to parse this file?
    every word is separated with a "\t". I used MyString.split("\t"), but is returns me back null value...
    What can you advise me?
    Thanks a lot!

    Well, here is the short code:
    private static int aX;
    private static int X;
          * @param args
         public static void main(String[] args) {
              BufferedReader entree = new BufferedReader( new InputStreamReader(System.in));
              String cmd = "";
              String type="";
              try {
                   cmd = entree.readLine();
                   String[] res = cmd.split("\t");
                   if(res[0]=="accelero"){
                        type="accelero";
                        aX = Integer.parseInt(res[1]);
                   else if(res[0]=="touch"){
                        type="touch";
                        X = Integer.parseInt(res[1]);
                        System.out.println("touch:"+X);
                   else if(res[0]=="0.0"){
                        type="data";
                   System.out.println(type);
                   System.out.println("accelero:"+aX);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              String[] rix = cmd.split("\t");
         }when you try this code, you should write (for example): accelero 35
    there is a \t between accelero and 35, and I want the system to print accelero, and 35 once the full string was split.
    System.out.println(type); --> prints nothing
    System.out.println("accelero:"+aX); --> prints accelero:0
    I want simply to use the res. It seems like the string.split doesn't work in this example.

  • How to parse ".dat" file using java?

    Hi experts/friends,
    I need to parse the ".dat" files such as "history.dat" of Firefox history and "index.dat" of IE history...
    I cannot able to parse those files.
    Can anyone suggest me or help me....

    Google ( [url http://www.google.com/search?q=firefox+history+file+format]firefox history file format )
    Google ( [url http://www.google.com/search?q=internet+explorer+history+file+format]internet explorer history file format )

  • How to parse Java File( Any Solution)

    Hi guys
    is it possible to parse java file ?
    Without reflection I want to get all methods, variables, inner class and its methods in my java file
    Pls reply if U have solution
    Raja Ramesh

    You can load it into javadoc, and write a doclet to walk the parsed data.

  • How to parse xml file to read the tags

    Hi All,
    I am having a requirement to read the tags from the xml file(xml parsing).
    The main issue is *xml file is stored in the table with xml type column* (not placed directly in the server) and we have to read the tags from that xml file.
    Please help me to achieve it.
    Regards,
    Akshata
    Edited by: Akshata on Mar 21, 2013 3:44 AM

    Hi,
    Akshata wrote:
    The main issue is xml file is stored in the table clob/blob type column (not placed directly in the server) and we have to read the tags from that xml file.How is that an issue? On the contrary, it's better when the data already resides in the database, though it should be in an XMLType column to leverage the full capacity of the Oracle parser.
    What's the datatype of the column exactly? CLOB or BLOB?
    Either way you'll have to convert in to XMLType datatype using the XMLType constructor.
    Did you go through the countless examples on this forum? Examples with XMLTable should be helpful.
    Post some sample data and database version if you need additional guidance.
    Thanks.

  • HOW TO PARSE RTF FILES ?

    Hi,
    I need some help regarding RTF files in Java. I need to parse content from RTF file and upload it into a database. i have been facing difficulty selecting the text out from the RTF file. Is there any API available in J2SE 1.3 which i could use to parse the text from the RTF files ?
    Help would be greatly apperciated
    Thanx
    Sampath

    You can find some RTF parsers at
    http://cobase-www.cs.ucla.edu/pub/javacc/

  • How to parse flat file

    What I have is a tab delineated file.
    Example -
    ACP     047     047     047     09072011     600058          MIX35     T6          097     429097068158900300     PLUS     12312011     TEST      JAMIE     1397090     0000000     000     001     000000     126969               BON/00439/:BAS/126500/:TEL/00030/TELECOMMUNICATIONS CHARGE
    But the last part - BON/00439/:BAS/126500/:TEL/00030/TELECOMMUNICATIONS CHARGE
    is one field and I need to break it down to separate fields - BON 00439 There is a implied field after 00439 then BAS 126500 then an implied field then TEL 00030 TELECOMMUNICATIONS CHARGE
    Can't figure a way to parse the record on sql.
    Using 10.2.
    Thanks in advance
    Paul

    The example you gave, is this the source file, or what you already loaded into the table?
    If that's the source file, load it into the table, every tabbed field into its own column. This way you will have the last column containing up to 5 groups of data. You will just have to split this column into 15 columns, the SQL for this is provided by BlueShadow:WITH A AS
    -- sample last column data
    SELECT 'BAS/02897/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' IN_RECORD FROM DUAL
    UNION ALL
    SELECT 'PLS/00900/:BAS/02600/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'BAS/02600/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'BAS/05100/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'BAS/02897/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'PLS/00900/:BAS/03800/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'BAS/02600/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'PLS/00250/:BAS/03500/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'BAS/02500/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    UNION ALL
    SELECT 'BAS/02900/:BON/00309/:TEL/00030/TELECOMMUNICATIONS CHARGE' FROM DUAL
    SELECT
      REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,1), '[^/]+',1,1) CT1
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,1), '[^/]+',1,2) CA1
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,1), '[^/]+',1,3) CD1
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,2), '[^/]+',1,1) CT2
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,2), '[^/]+',1,2) CA2
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,2), '[^/]+',1,3) CD2
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,3), '[^/]+',1,1) CT3
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,3), '[^/]+',1,2) CA3
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,3), '[^/]+',1,3) CD3
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,4), '[^/]+',1,1) CT4
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,4), '[^/]+',1,2) CA4
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,4), '[^/]+',1,3) CD4
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,5), '[^/]+',1,1) CT5
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,5), '[^/]+',1,2) CA5
    , REGEXP_SUBSTR(REGEXP_SUBSTR(IN_RECORD,'[^:]+',1,5), '[^/]+',1,3) CD5
    FROM A
    CT1                                                                  CA1                                                                  CD1                                                                  CT2                                                                  CA2                                                                  CD2                                                                  CT3                                                                  CA3                                                                  CD3                                                                  CT4                                                                  CA4                                                                  CD4                                                                  CT5                                                                  CA5                                                                  CD5                                                               
    BAS                                                                  02897                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    PLS                                                                  00900                                                                                                                                     BAS                                                                  02600                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                          
    BAS                                                                  02600                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    BAS                                                                  05100                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    BAS                                                                  02897                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    PLS                                                                  00900                                                                                                                                     BAS                                                                  03800                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                          
    BAS                                                                  02600                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    PLS                                                                  00250                                                                                                                                     BAS                                                                  03500                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                          
    BAS                                                                  02500                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    BAS                                                                  02900                                                                                                                                     BON                                                                  00309                                                                                                                                     TEL                                                                  00030                                                                TELECOMMUNICATIONS CHARGE                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    10 rows selected

  • How to parse jsp file

    What is the way to prase a JSP file which is in the local drive using a parser inorder to extract some information?.
    For example :
    <%@ page info=" hello world " %>
    <html>
    <head><title>Hello, World</title></head>
    <body bgcolor="blue" >
    <%@ include file="index.html" %>
    <table>
    <tr>
    <td width=150> </td>
    <td width=250 align=right> <h1>Hello, World!</h1> </td>
    </tr>
    </table>
    </body>
    </html>
    What i want to do is to print the "title" of the page and the "file" which is in the tag <%@ include file="index.html" %>.
    Thank you in advance.

    A JSP file is run, not parsed.Ususally a servlet source is generated from the jsp file, it is compiled, and run. Now in order to turn the jsp file into a servlet (code), it has to be (at least partially) parsed first.

Maybe you are looking for