Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

about reading content out of the file

Posted on 2004-10-26
8
Medium Priority
?
164 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
Comment
Question by:tom_mk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 1000 total points
ID: 12408238
Read line by line (String) and split up the line in its components using line.split(",")
0
 
LVL 92

Assisted Solution

by:objects
objects earned 1000 total points
ID: 12408241
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
ID: 12408250
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tom_mk
ID: 12408279
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
ID: 12408313
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
ID: 12408315
if (line.startsWith("//"))
{
   // ignore
}
else
{
  ...
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

597 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