Solved

about reading content out of the file

Posted on 2004-10-26
162 Views
Last Modified: 2010-03-31
here is the pattern of the file i wanna get the content out.

--------------------------------------------------------------------------------------------------------
0,aldeg_cas01.gat,Noisy ubantian,1
1,aldeg_cas02.gat,Hohensyubangawoo,1
2,aldeg_cas03.gat,Nyir enverk,1
3,aldeg_cas04.gat,Byirts buri,1
--------------------------------------------------------------------------------------------------------

i wanna know the most efficiency method to get the content out of this kind of file.
should i just use array? or s.t else?
and another problem , will the space in the 3rd column b any problme if i didn't use string for that?

can any1 suggest me a good code for doing this?

0
Question by:tom_mk
    6 Comments
     
    LVL 37

    Accepted Solution

    by:
    Read line by line (String) and split up the line in its components using line.split(",")
    0
     
    LVL 92

    Assisted Solution

    by:objects
    BufferedReader in = new BufferedReader(new FileReader("file.txt"));
    String line = null;
    while (null!=(line=in.readLine()))
    {
       String[] tokens = line.split(",");
       // use data as required
    }
    in.close();
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    try {
            BufferedReader in = new BufferedReader(new FileReader("<your file>"));
            String line;
            while ((line = in.readLine()) != null) {
                String parts[] = line.split(",");
                for (int i=0; i<parts.length; i++)
                   System.out.println(parts[i]);
            }
            in.close();
        } catch (IOException e) {
        }

    >> will the space in the 3rd column b any problme if i didn't use string for that?
    ???
    The content of your file is String, isn't it?
    0
     

    Author Comment

    by:tom_mk
    thx guys... very fast..

    another sub question

    says, in my file
    i have some comment on top, just wanna put there .
    and i need my prog to ignore that part while reading thru my file

    how can i do that?
    below is the example

    thxxx very much

    -------------------------------------------
    //ƒMƒ‹ƒhéƒf[ƒ^ by sakage,shuto
    // AgitDB Modify by Michael_Huang at 2004-02/13.
    // <Castle_ID>,<Map_Name>,<Castle_Name>,<Switch_Flag:(reserved)>
    0,aldeg_cas01.gat,Noisyubantian,1
    1,aldeg_cas02.gat,Hohensyubangawoo,1
    2,aldeg_cas03.gat,Nyirenverk,1
    3,aldeg_cas04.gat,Byirtsburi,1
    4,aldeg_cas05.gat,Rotenburk,1
    5,gefg_cas01.gat,Reprion,1
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    try {
            BufferedReader in = new BufferedReader(new FileReader("<your file>"));
            String line;
            while ((line = in.readLine()) != null) {
                if (line.startsWith("//") continue; // <<<<<<<<<<<<<<<<<<<
                String parts[] = line.split(",");
                for (int i=0; i<parts.length; i++)
                   System.out.println(parts[i]);
            }
            in.close();
        } catch (IOException e) {
        }
    0
     
    LVL 92

    Expert Comment

    by:objects
    if (line.startsWith("//"))
    {
       // ignore
    }
    else
    {
      ...
    }
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now