CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Reading data.

  1. #1
    Join Date
    Sep 2011
    Posts
    197

    Reading data.

    Are there any api's to connect a method to a document to read data from it. Lets say I want the program to save all user names. And, display them if requested. I store all usernames in usernames.txt, how do I access the file's data?

    I am only asking for some API's not the code to do it.

  2. #2
    Join Date
    Apr 2007
    Posts
    442

    Re: Reading data.

    A number of APIs. For a simple text file, Scanner is a convinient and easy to use approach. You can create a Scanner for the file, iterate it line by line in a while loop. If your file format is more complex (ie containing username, address, age, id-number etc.... various different types) you can pass each line to a new Scanner and ask like...

    name=scanner.next();
    age=scanner.nextInt();
    id= scanner.nextLong();

    Since you handle the writing yourself as well (?), you are certain in which order the items occur in the file.

    It might be worthwhile to also check how to do the same using methods contained in the wrapper classes (Integer for int and so on) and String. You can also experiment how to read the contents of the file using Reader instances / various InputStream instances. But for all sh**s and giggles, Scanner is a decent approach for your problem.

  3. #3
    Join Date
    Sep 2011
    Posts
    197

    Re: Reading data.

    I think I'm looking for more of a listner class. I was looking through scanner, and it seems to be for reading text, not data (data meaning information for the program to use while executing). I need it to be able to execute certain methods from the data for example. If the program reads __start05 initiate the method with 05 as it's parameters. I am open to using scanner and, a listner to facilitate my needs, but I wanted to be sure there was nothing readily available.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured