Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Reader

 
Gerhard Abrahams
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to get the stuff from my TextArea into a text file now I would like to open the same file using the FileReader and load it into the TextArea.
Yet when I try I get a compilation error. Incompatible types.
The complete code is below and it happens in the Open class
What is it I am doing wrong again?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

String inhalt;
while ((inhalt = einlesen.read())

"read" returns int (not char, so that it can hold either a character or -1 to indicate EOF.) Trying to assign this int to "inhalt", which is a String, gives the incompatible type error.
There are a number of ways to do this; probably what you want to do is use something like

This reads in a chunk of characters at a time rather than just one, so it's far more efficient.
 
Gerhard Abrahams
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks very good to me gives me some ideas for the sorting algorithm too. I keep on trying. Thank you for your quick reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic