reading from file...seems to be agille


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: reading from file...seems to be agille

  1. #1
    Join Date
    Oct 2002
    Posts
    13

    reading from file...seems to be agille

    Hi,
    i have a problem, well it's more a question. I shall write short prog. that will read a text file consisted of words separated with emty space. I know about tokens and I was intended to use them, but a friend of mine suggested me another option, but without any example.
    He realized, that there are only 2 words that i need to know. Both are always in the first half of line. So he suggested to read the line not by words but chars and after reading what i need to jump on next line.
    So he wanted to shorten somehow reading the file.

    the line looks like that

    servername date time numberofhits exactdirectoryopened...

    Is his idea possible or should I rather use tokenizer?

  2. #2
    Join Date
    Sep 2002
    Posts
    78
    try
    {
    InputStreamReader isr=new InputStreamReader(new FileInputStream(new File("Test.txt")));
    char c;
    int i=0;
    while((i=isr.read())!=-1)
    {
    c=(char)i;
    }
    isr.close();
    }
    catch (IOException ioe)
    {
    System.err.println(ioe);
    }

    this will read 1 char at a time from your file until it reaches the end of the file, hopefully this will help you get what u need.
    ¿Red Baron?
    [code] /* dont forget code tags! */ [/code]
    Come visit the Café!

  3. #3
    Join Date
    Oct 2002
    Posts
    13
    Originally posted by Red Baron
    try
    {
    InputStreamReader isr=new InputStreamReader(new FileInputStream(new File("Test.txt")));
    char c;
    int i=0;
    while((i=isr.read())!=-1)
    {
    c=(char)i;
    }
    isr.close();
    }
    catch (IOException ioe)
    {
    System.err.println(ioe);
    }

    this will read 1 char at a time from your file until it reaches the end of the file, hopefully this will help you get what u need.

    thx, will try...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center