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,