Cannot find symbol

Hi,

I'm getting this error when i use Out.writeUTF("Hello");

I have imported

import java.io.*;

import java.util.*;

This is the error message that im currently getting.

C:\Program Files\Java>javac Encoder.java

Encoder.java:52: cannot find symbol

symbol : method writeUTF(java.lang.String)

location: class java.io.OutputStream

Out.writeUTF("Hello");

Is there something i need to import.

Im not really sure.

Thanks.

[503 byte] By [carrics3a] at [2007-11-27 1:40:03]
# 1
Out if of type OutputStream. writeUTF is probably referring to interface DataOutputwhich is implemented by a number of popular classes, like DataOutputStreamand ObjectOutputStream.
DrLaszloJamfa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 2
Yes i have created out like soDataOutputStream Out = new DataOutputStream(new FileOutputStream(args[1]));i then call later in my programOut.writeUTF(firstVal);
carrics3a at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 3
Yes, that should work.
DrLaszloJamfa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 4
Yeah i thought that would work.But this is giving me the above error and i dont understand why?Is there something im supposed to import?or a class im missing?
carrics3a at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 5
Try deleting your *.class files and recompiling. If that doesn't work,post a small (<1 page) sample program that demonstrates your problemand that forum members can copy and run.
DrLaszloJamfa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 6

Hi,

I made a sample program and the writeUTF() works.

But i cant figure out why it wont work for other program

Here is the part of the program where i call the writeUTF() function

public void encode(InputStream In, OutputStream Out, Hashtable<String, Integer> dictionary)throws IOException

{

try{

int dictionarySize = 256;

int reader = 0;

String addVal="";

//byte[] convertedVal;

String firstVal= (char)In.read()+"";

while(In.available()>0)

{

reader=In.read();

if(dictionary.containsKey(firstVal + (char)reader)){

firstVal = firstVal + (char)reader;

System.out.println("Im Here");

}

else

{

System.out.println("Im here 2");

Out.writeUTF(firstVal);

addVal = firstVal + (char)reader;

dictionary.put(addVal, dictionarySize);

firstVal = (char)reader+"";

dictionarySize++;

}

}

Out.writeUTF(firstVal);

System.out.println("Dictionary Size is now "+dictionarySize);

}

catch(IOException e){

e.printStackTrace();

}

}

carrics3a at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 7
You claimed out was of type DataOutputStream, but in this code, it is merely of type OutputStream.
DrLaszloJamfa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 8
Hi..I see that now..School boy error.Thanks for your quick reponse.Cheers
carrics3a at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 9
The file that im writing to doesnt contain the outputted data.I am closing the file before the program terminates.Is there anything else i need to look out for?
carrics3a at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 10
As my pappy always said: don't forget to flush!stream.flush();stream.close();
DrLaszloJamfa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 11
> As my pappy always said: don't forget to flush!> > stream.flush();> stream.close();> No flush necessary. Just close() it and that will take care of the flush internally.
warnerjaa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 12
I know for Writer the close method is documented that it "Closes the stream, flushing it first."But is that true for OutputStreams?
DrLaszloJamfa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 13
Yep thats works.Cheers
carrics3a at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...
# 14
> I know for Writer the close method is documented that> it "Closes the stream, flushing it first."> But is that true for OutputStreams?For ones needing to be flushed (buffered ones only), yes. If not, we're all in big trouble.
warnerjaa at 2007-7-12 0:53:49 > top of Java-index,Java Essentials,Java Programming...