about reading content out of the file

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?

tom_mkAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
zzynxConnect With a Mentor Software engineerCommented:
Read line by line (String) and split up the line in its components using line.split(",")
0
 
objectsConnect With a Mentor Commented:
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
 
zzynxSoftware engineerCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
tom_mkAuthor Commented:
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
 
zzynxSoftware engineerCommented:
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
 
objectsCommented:
if (line.startsWith("//"))
{
   // ignore
}
else
{
  ...
}
0
All Courses

From novice to tech pro — start learning today.