Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot resolve method println()  RSS feed

 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I want this program to write a String, an Integer, a Float, and a Character on separate lines in a Random Access File. I went on the java-sun website and decided to experiment with the println() method.



...but the complier tells me: cannot resolve symbol method println(). Why?
 
Andrew liu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the api, there isn't a method named "println" in the class RandomAccessFile. If you want to write something to the file, you can use the methods headed "write".
 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I know. But the only problem with the write() method is that it sticks all the variables in one line. I want to put each variable on a separate line. I know that I can just do something like:

raf.writeInt(the_integer);
raf.writeBytes("\n");
etc...


But I want to know if there's an alternative.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Olivier Legat:
I want to put each variable on a separate line. I know that I can just do something like:

raf.writeInt(the_integer);
raf.writeBytes("\n");
etc...


But I want to know if there's an alternative.


If that is all you want, why can't you just write a method for it? Write you own println(), that takes a parameter, which... writes the parameter then write the CRLF.

Henry
[ November 24, 2007: Message edited by: Henry Wong ]
 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I've thought of doing that, but I just wanted to make sure that there isn't already a pre-defined method that does that.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
println() doesn't make logical sense for a Random Access File - there is no concept of "line" in files that are random access.

If you want your data 0x00 terminated or "\n" terminated in sections that don't "use the whole block" that's just convention.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!