Results 1 to 2 of 2

Thread: [java] general object questions

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default [java] general object questions

    Hello,

    I'm writing a program. It must read many files and for each he must split their content in tokens ( the blank space is the delimiter). Now I think to use scanner Object to work on this; and I'm wondering about the file reading: what better? I suppose doens't make sense to read every file into a block and then Scanner it !? Or it's better open a file, read a file, scanner a single line and go on till the end of the file (this for all file);
    Then I must work on the tokens of all files: so I think to put every tokens in a Vector.
    Furthermore, How do you implement it ? I mean:I suppose to have something like:
    Qt Code:
    1. class FileToText {
    2. static public String readString file){
    3. StringBuilder sb = new StringBuilder();
    4. try {
    5. BufferedReader in = new BufferedReader(new FileReader(new File(file) ));
    6. try {
    7. String s = null;
    8. while (( s = in.readLine()) != null) {
    9. sb.append(s);
    10. }
    11.  
    12. } finally { in.close(); }
    13. } catch (IOException e) {
    14. System.out.println("file not found");
    15. System.exit(-1);
    16. }
    17. return sb.toString();
    18. }
    19. }
    20. //main
    21. Scanner scanner = new Scanner ( TextFile.read( "file.txt") );
    To copy to clipboard, switch view to plain text mode 
    Maybe it doesn't make sense read line by line and after scanner it....How do you do this, please?

    thanks,
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: [java] general object questions

    hi,

    do anybody help me or any hints, please?
    Regards

Similar Threads

  1. QGraphicsView general questions
    By sincnarf in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2007, 23:22

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.