DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2005
    Posts
    115

    Reading from a file

    Lets say i have a file "userDistance.txt" with the contents:

    Legend:
    A B C D E

    Distance:
    {0}
    {10 0}
    {11 12 0}
    {11 12 13 0}
    {11 12 13 14 0}

    Using Scanner and FileInputStream, how do i extract the data for legend and distance and store:
    1. ABCDE in to String called legend
    2. The distance matrix into a multidimensional array

    I have tried things like
    Code:
    if(inputStream.next()=="Legend:")
    
    or nextLine()
    To detect the 1st line with the word Legend and extract all the characters after Legend, but it doesnt work.

    Please help, thx guys...
    Last edited by Ant_Magma; 08-26-2005 at 03:52 PM.

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    This help you get started:

    Code:
    BufferedReader in = new BufferedReader(new FileInputStream("userDistance.txt"));
    
    String key = in.readLine();
    if (key.equals("Legend"))
    {
        //break the string up into tokens using a "space" as the delimiter
        String[] legend = in.readLine().split(" ");
    }

  3. #3
    Join Date
    May 2005
    Posts
    115
    Oh Phaelax, thx man..after reading ur code i guess i know what was wrong with mine..

    I used == instead of equals. I keep on forgetting that String is an object..

Similar Threads

  1. Replies: 2
    Last Post: 11-14-2001, 12:49 PM
  2. Replies: 3
    Last Post: 08-23-2001, 11:01 AM
  3. How to use Java to lock a file
    By Cynthia Leslie in forum Java
    Replies: 3
    Last Post: 06-09-2001, 06:43 PM
  4. Correction: Reading Summary/Shortcut File Properties
    By Millard Melnyk in forum VB Classic
    Replies: 8
    Last Post: 06-03-2000, 03:03 PM
  5. Correction: Reading Summary/Shortcut File Properties
    By Millard Melnyk in forum VB Classic
    Replies: 0
    Last Post: 06-02-2000, 02:12 PM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links