Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing a String  RSS feed

 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to write a string to a file: Below is the coding I used:



Error Message:
FileOutputStreamEx.java:8: cannot resolve symbol
symbol : method getBytes ()
location: class FileOutputStreamEx
fos.write("Hello",getBytes());
^
1 error

Another question: How to find whether particular methods resides in which package. For example, if i want to know in which package the getBytes() methods is resides. Though I downloaded and API, it's diifcult for me to search. Is there any to find the particular classes, interfaces and methods more easily.
 
Choon-Chern Lim
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get the APIs, go to http://java.sun.com/j2se/1.4.2/docs/api/

If you have using Eclipse to write your java, do a CTRL + SPACE and it will give you the intellisense on the selected object.

As for writing a string to a file, consider using printwriter as it allows you to write a whole line instead of character by character.


 
Norm Radder
Rancher
Posts: 1733
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler is complaining that it can NOT find a definition for the method getBytes().
If getBytes() is not defined in the current scope of your program where you reference it, you must tell the compiler where to find it.
I suspect that you mean to call that method of a String object.
Where is that String object? Should the , be a . before getBytes() so that the "literal" is the String object you're refering to?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15859
80
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Norm says the problem is probably the comma ',' instead of dot '.'

Also, don't forget to flush and close the output stream.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!