I have to "Convert" a file to a String.
Do I have to use readLine and add every line or have Java a better way?
Printable View
I have to "Convert" a file to a String.
Do I have to use readLine and add every line or have Java a better way?
You have to convert a whole file ot a string :confused: For what purpose? Im just curious. :p
I am making a application to calculate how easy it is to read a text
and somtime i have a string ond sometime i have a text file .
in the class a use a string and here i have to calculate the numbers of word, nombers of longWord (>=7 char.) and mombers og word in a sentens.
Sounds like you're writing the "Fog Index" program.
Reading in the whole text may someday be practical when memory becomes much cheaper, say, ten years from now, but if you write this program and run it today, it'll be limited. It might be kind of fun to download a novel off the net and check it's reading level, but you may not be able to do this with your program as you propose it if you read in the whole text as a string because of exceeding memory.
To improve the utility of your code, it would probably be a simple matter of taking your existing program that operates on a single string and putting a while loop around it so that it reads in many strings. Then from the heart of the program, remove the summary line that prints the results and move it so that it appears just after the loop. In this manner, every time you read a string, you can then keep a running tally of the results. Then when the program has completed reading the text file, it can report the results.
cudabean