• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

cannot resolve method println()

 
Ranch Hand
Posts: 176
Mac Chrome 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?
 
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
Mac Chrome 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.
 
author
Posts: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Mac Chrome 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.
 
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!