Way to use data from text file?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Way to use data from text file?

  1. #1
    Join Date
    Feb 2003
    Posts
    13

    Way to use data from text file?

    I was wondering if there was a way that you could use data from a .txt file in Java. Any help would be great.

    Thanks,
    Brad

  2. #2
    Join Date
    Mar 2003
    Posts
    84
    um, yeah. you can pretty much do whatever you want with it.

    can you be more specific.


    data in a text file could be anything, and you could do anything with it.

    read it in, modify it.
    make calculations and assumptions based on it.


    I actually wrote a compiler program that created java source code.. it was a 3rd lvl language compiler that used a txt file that contained a list of variable types and names

    and it output .java file that were ready to compile with accessors and mutators for every variable.. as well as generic comment lines and a generic header. it also input the proper api's so that the .java files were ready to compile.
    I'm surprised more of you people don't get hit by cars.

  3. #3
    Join Date
    Feb 2003
    Posts
    13
    Thanks for replying. I'll try to be more specific. The file is a .ct file that can be opened in wordpad. The file contains numbers that are separated into columns and rows. How can I import this data in an organized fashion so that I could use it in the program?

    Thanks,

    Brad

  4. #4
    Join Date
    Mar 2003
    Posts
    84
    Read the API on BufferedReader and FileReader to read in the contents of the file.

    And then read the API on StringTokenizer to separate the columns of data and parse them and cast them appropriately.
    I'm surprised more of you people don't get hit by cars.

  5. #5
    Join Date
    Mar 2003
    Posts
    84
    Here's a hint to what I mean.

    Code:
    BufferedReader reader = new BufferedReader(new FileReader("nameOf.file");
    String line;
    StringTokenizer tokens;
    
    
    line = reader.readLine();
    while(line != null)
     {
     tokens = new StringTokenizer(line, "\t");
     //   here you call tokens.nextToken() to get the 
     //   separate chunks of data.. and store them wherever 
     //   you want to.
    
     reader.readLine();
     }
    I'm surprised more of you people don't get hit by cars.

  6. #6
    Join Date
    Feb 2003
    Posts
    13
    Thanks for all of your help Fantik.... I'll make sure to read the API on those and thanks for the example... it looks like it will help.

    Brad

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