Forums Register Login

problems reading a file in a required way

+Pie Number of slices to send: Send

I'm trying to read this file:

Distinguido/a cliente:

Le damos la bienvenida a nuestra empresa y deseamos que nuestra relación sea siempre muy satisfactoria.

Muy atentamente,

El director


and it's obligatory to do it as if the words in the file were "Paraula" objects. This is the class Paraula:


And I have this class to read the files:


The problem is that I need to read the file and then write the content in another file, but it doesn't read "\n" "\r" so when I write it the source file appears in the new file in just one line. How can I do it to make it "save" or know when the char read is a '\n' to write it in the new file and still using this method of reading as if the words were Paraula objects?

Thank you
+Pie Number of slices to send: Send
Why are you reading char by char? Why are you using a char[]? Look at this part of the Java® Language Specification. By the time you have worked this out, you should have an implacable hatred of the read() method.
Don't use chars. Don't use char[]s. Use Strings. If you want individual words use the next() method of Scanner. You can use the nextLine method to read whole lines, but if you use nextLine after nextAnythingElse, there is a risk of returning the empty String.

You should not create equals methods other than the Object#equals() method.
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 500 times.
Similar Threads
problems when trying to write an object in a file (not serializable exception)
reading a file using a class
BufferedReader is not Serializable?
problems adding keyListener to JFrame class
transform and change the words of a file.txt with java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:15:29.