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.

Similar Messages

  • How to parse text file (.eml) to get index of line, that contains Subject, From field, and base64 decoded Body

    Hello, Dear Colleagues.
    Help me please with next deal.
    As input I have .eml file:
    x-sender: [email protected]
    x-receiver: ***************************
    Received: from ***** with Microsoft SMTPSVC(7.5.7601.17514);
    Fri, 20 Mar 2015 12:43:03 +0200
    In-Reply-To: <********@LocalDomain>
    To: *****************************
    Bcc:
    Subject: Incident ID#: 117 Something wrong, something right, something missing
    Message-ID: <*****************************@LocalDomain>
    From: [email protected]
    Date: Fri, 20 Mar 2015 12:42:55 +0200
    Content-Type: multipart/related; boundary="=_related ********************"
    References: <*******************************C@LocalDomain>
    MIME-Version: 1.0
    X-KeepSent: ****************************; name=$KeepSent; type=4
    X-Mailer: Lotus Notes Release 8.5.2FP3 July 11, 2011
    X-Disclaimed: 54023
    Return-Path: [email protected]
    X-OriginalArrivalTime: 20 Mar 2015 10:43:03.0590 (UTC) FILETIME=[A48E9C60:01D062FA]
    --=_related **********************=
    Content-Type: multipart/alternative; boundary="=_alternative &**************"
    --=_alternative ******************
    Content-Type: text/plain; charset="KOI8-R"
    Content-Transfer-Encoding: base64
    U29tZXRoaW5nIHdyb25nLCBzb21ldGhpbmcgcmlnaHQsIHNvbWV0aGluZyBtaXNzaW5nDQpTb21l
    dGhpbmcgYmxhY2ssIHNvbWV0aGluZyBsaWdodCwgc29tZXRoaW5nIGRpZmZlcmVudA0KRG9uJ3Qg
    eW91IGV2ZXIgZmVlbCB5b3UgbmVlZCB0byBzcGVhayB0byBtZSB0aGF0IHdheT8NClNvbWV0aGlu
    ZyBibGFjaywgc29tZXRoaW5nIGxpZ2h0LCBzb21ldGhpbmcgZGlmZmVyZW50DQpTb21ldGhpbmcg
    d3JvbmcsIHNvbWV0aGluZyByaWdodCwgc29tZXRoaW5nIG1pc3NpbmcNCkRvbid0IHlvdSBldmVy
    IGZlZWwgeW91IG5lZWQgdG8gc3BlYWsgdG8gbWUgdGhhdCB3YXk/IA==--=_alternative ******************
    Content-Type: text/plain; charset="KOI8-R"
    Content-Transfer-Encoding: base64
    Because position of lines changes due to email type, as output I want to get:
    1). index of line that contains: Subject, i.e. "Subject: Incident ID#: 117 Something wrong, something right, something missing"
    2). index of line that contains "From", i.e. "From: [email protected]"
    3). base64 - decoded text (body of email)
    Thanks for your help.
    Have a nice day.

    jrv,
    your script, unfortunately, always return "String not found".
    Because you file is probably not constructed the same as the copy you posted.  I was just showing you how.  You will need to adjust to the actual file.
    Outlook can open and convert  EML files. 
    ¯\_(ツ)_/¯

  • How to write text file in Shockwave?

    Does anybody know how to write text file in Shockwave to
    user's disk?
    Thanks in advance.

    Those Xtras can wreak to much havoc when used with the wrong
    intent.
    What you can do is write with setpref and store a list of
    saves and the
    saves itself seperatly. Then you'd have to build your own
    save/open
    dialog to let the user:
    * pick a previously saved file to load or overwrite
    * have the user type the name of a new file to save.
    Only thing that remains is that the user cannot decide where
    the files
    are saved.
    Manno
    SiuLinda wrote:
    > Thanks a lot for your reply.
    > Yes, cookies is good but I have to write a program to
    save the text file in
    > where the user wants, user can open these files later if
    they like, like using
    > Filextra and Fileio, but I found all of these xtras seem
    to be not supported in
    > shockwave.
    >
    Manno Bult
    [email protected]

  • 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 read text file line by line...?

    how to read text file line by line, but the linefeed is defined by user, return list of string, each line of file is a item of list?
    please help me.
    Thanks very much

    Brynjar wrote:
    In Groovy, you would do something like:
    linefeed = "\n" //or "\r\n" if the user chose so
    lines = new File('pathtofile').text.split("${linefeed}")This is one of the things that has always annoyed me about Sun's sdk, i.e. the lack of easy ways to do things like that. You always end up making your own utilities or use something like Apache's commons.io. Same goes for jdbc and xml - I'll wait for appropriate topics to show how easy that is in Groovy :)I generally agree, but what I really don't like about the Groovy text-file handling niceties: They don't care about encoding/always use the default encoding. And as soon as you want to specify the encoding, it gets a lot more complex (granted, it's still easier than in Java).

  • How to load text file data to Oracle Database table?

    By using Oracle Forms, how to load text file data to Oracle Database table?

    Metalink note 33247.1 explains how to use text_io as suggested by Robin to read the file into a Multi-Row block. However, that article was written for forms 4.5 and uses CREATE_RECORD in a loop. There was another article, 91513.1 describing the more elegant method of 'querying' the file into the block by transactional triggers. Unfortunately this more recent article has disappeared without trace and Oracle deny its existence. I know it existed as I have a printed copy in front of me, and very useful it is too.

  • How to load text files in GUI

    plz tell me .. how to load and compare two text files using file popup's . example file i have attached..
    Attachments:
    testW_FF.txt ‏2 KB

    I don't understand whether your question is on how to load text files or how to show them on a panel or how to compare them... or all aspects together!
    The first operation (loading the file) can be accomplished with functions included in the Formatting and I/O Library like OpenFile, ReadFile and so on; with a file like yours even FileToArray could be an option.
    How to show the data on screen is heavily dependent on what you intend to do with them: data can be shown in textboxes, listboxes, tables or graphs so... what do you want to do?
    The same applies with comparison: without additional details is difficult to give you the proper hint.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Step by Step"How JSP read text file :

    Hi ,
    Any one know or have a good site to show step by step how JSP read text file.
    TQ.

    There is no difference Between reading a text file from JSP and reading a text file from Java.
    Just follow the same steps for JSP also.

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Parse TEXT File??

    Hi,
    I am using CF 8
    I have a text file (mylog.txt) that currently stores login
    information for our users. I need to parse and extract some basic
    information from the file and I am having a hard time. I need to
    know the following
    1. A list of all UNIQUE email addresses that appear in the
    text file.
    2. A count of how many times each email address appears
    Each time a user logs on a "new line" is entered in the text
    file. Here is some sample data:
    [1/05/08 1:15:31 PM] User [email protected] logged in.
    [1/11/08 3:57:30 PM] User [email protected] logged in.
    [1/12/08 8:33:17 PM] User [email protected] logged in.
    [2/17/08 6:37:07 AM] User [email protected] logged in.
    [2/19/08 3:57:30 PM] User [email protected] logged in.
    I would like to parse the text file and then output my
    results to the screen. The output should look like this, note John
    logged in twice:
    Email Address | Count
    [email protected] 1
    [email protected] 2
    [email protected] 1
    [email protected] 1
    The prior user here should have stored this in the database
    but for now I still need to get at this data.
    Any help appreciated.
    Thanks,
    -Westside

    You can use cfhttp to convert your file variable to a query
    and use query of queries to count email adddresses.

  • How to parse text and build object node

    Dear All,
    I have a text file as following. I have tried with one node to parse it and store the information. But I can not parse when I have put multiple node. Could you please suggestion me or help on this. How can I store information according node by reading this text file.
    Thanks in advance .
    AUM
      file1.txt
    abattoirs
         TNR: 3786
          BT: buildings
          RT: abattoir workers
          RT: meat byproducts
          RT: meat hygiene
          RT: meat inspection
          RT: meat production
          RT: meatworks effluent
          RT: slaughter
          RT: slaughterhouse waste
          RT: slaughtering equipment
    abdomen
         TNR: 3792
          BT: body regions
          NT: umbilicus
          RT: abdominal cavity
          RT: belly
          RT: body cavities
          RT: laparotomy
          RT: peritoneum
    abdominal cavity
         TNR: 3793
          BT: body cavities
          RT: abdomen
    public class TextParser {
        public static String BT;
        public static String RT;
        public static String NT;
        public static void main(String[] args) throws IOException {
            FileInputStream fis = new FileInputStream("C:/file1.txt");
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
            while (true) {
                String line = reader.readLine().trim();
                if (line.startsWith("BT")) {
                    String bt[] = line.split(":");
                    System.out.println("BT="  +bt[0]);+
    +                System.out.println("Value="+  bt[1]);
                } else if (line.startsWith("RT")) {
                    String rt[] = line.split(":");
                    System.out.println("RT="  +rt[0]);+
    +                System.out.println("Value="+  rt[1]);
                } else if (line.startsWith("NT")) {
                    String nt[] = line.split(":");
                    System.out.println("NT="  +nt[0]);+
    +                System.out.println("Value="+  nt[1]);
                } else {
                    System.out.println(" this is system");
    }

    aum1471 wrote:
    My problem is storing this large number txt file. I have started but I do not understand how I can create node after reading this files and store information one basis of
    node 1
    node 2
    so on. .. .Your question is still not entirely clear, but it sounds like you're looking for a Map (if you want to access various nodes by arbitrary names) or an array or ArrayList (if you want random access to nodes by index) or a general List (if you want to access nodes sequentially in the order in which you read them) or Set (if you want only one of each node, and don't care about the order).
    Google for java collections tutorial and java arrays tutorial.

  • 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!!!

  • Parsing text file with SGML tags

    <EMAIL>
    <ADDRESS>>[email protected]
    <DESC>>Email your questions to Click Here to E-mail
    <POP>
    <ADDRESS>N/A
    <ZIP>N/A
    How do you parse above text file which has SGML tags ? thanks

    Oh, sorry, if it's not an XML-file, then you properbly should use another approach. Where does the file come from? Could you properbly make it be a xml file ? ;-)
    Possible approaches are:
    * StringTokenizer, possibly with returning delimiters option enabled
    * good old make-it yourself indexOf/substring-method, ok... complicated
    * if you would like to handle the contents exactly like xml you could add a <?xml version="1.0"?><root> in the beginning and a </root> in the end and still use an xml parser, but keep character encodings in mind here.
    * another quite simple way that properbly fits best is java.util.regex API. if you want to use it, I can give you the code. it's easy.
    regards
    sven

  • Parse text file and retrieve data

    Hi,
    I have a log file with comma separated entries in each line. Each line has about 50 or more integer values logged for statistical analysis. What i need to do is to be able to parse this text file Line by line and retrieve data say nth entry in each row of file. Basically, like i need a certain column from a table. Column selection may vary. I can have user need 10th entry or 25th entry or more than one entries.
    Please help me with suggestions for how to do this efficiently . Keep in mind log file can be huge at certian times.
    Thanks
    -Anupma

    here's something to get you started
    public void parseFile(File file) throws IOException{
        String lin = null;  // string to hold each line in the text file
        BufferedReader in = new BufferedReader(new FileReader(file));
        while ((line = in.readLine()) != null){
            processLine(line);
    public void processLine(String line){
        String tokens = line.split(",");     // tokenize the line - deliminator is a comma
        for (int i = 0; i < tokens.length; i++){
            try{
                int num = Integer.parseInt(tokens);
    System.out.println(" The integer is = " + num);
    catch(NumberFormattedException ee){}

  • Parse Text-File into array

    Hi,
    I hava a text-file with a structure like this.
    "sfdgasdf" "sadsadsadf" "sadfsdfasfd"
    "qwevsdf" "sdgfasdfsafd" "yxvcyxvcyxvc"
    "hgfddfhhfdfdf" "ewrtqwrwqewqr" "dfgdgdgsdgsdfgsdgg"
    My aim is to read this text-file (*.txt) and parse it into an string-array (or whatever is the best). The contents between the apostrophes should be inserted in this array line by line.
    For example:
    array[0][0] = "sfdgasdf";
    array[0][1] = "sfdgasdf";
    array[0][1] = "sadfsdfasfd";
    array[1][1] = "qwevsdf";
    How can I achieve this?
    Thanks
    Jonny
    That's how far i came (not very far).
    File file = new File("c:\temp\text.txt");
    FileReader stream = new FileReader(file);

    Hi,
    still facing some problems.
    My text which I want to parse:
    "sfdgasdf" "sadsadsadf" "sadfsdfasfd"
    "qwevsdf" "sdgfasdfsafd" "yxvcyxvcyxvc"
    "hgfddfhhfdfdf" "ewrtqwrwqewqr" "dfgdgdgsdgsdfgsdgg"
    My code:
    String[] parse = text.split("\"");
    The array that is created has whitespaces and linebreaks as elements. I only want the characters in beween the apostrophes.
    How can I "tell" the split function not to insert them in my array?
    Cheers
    Jonny

Maybe you are looking for