• Post Reply Bookmark Topic Watch Topic
  • New Topic

problems reading a file in a required way  RSS feed

 
Johnny Januan
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!